1

I am using ajax call in jquery to handle some database operations, in ajax code I have a alert on error property, which gives my error message, but I want to know what the error was?

here is my ajax code

    $.ajax(
    {
            type: "POST",
            url: "server/assign_gifts_get_usr_details.php",
            data: "",
            success: function(xml)
            {
                    alert(xml);
            },
            error: function()
            {
                alert("Error, Please try again");   
            }
    });

this alert is popping up, alert("Error, Please try again");

but I want to know the error.

Pramod
  • 2,828
  • 6
  • 31
  • 40

2 Answers2

4

Well if it is getting to the error part of your code then the page was not able to load correctly.

That is basically the error.

There are also arguments that are passed to the error callback which you can use as well.

See the docs

The error callback gets the following arguments passed in: (jqXHR, textStatus, errorThrown)
From the docs:

A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event.

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

Do it like this, to get error details.

error: function(jqXHR, textStatus, errorThrown)
{
  alert("Error: "+errorThrown+" , Please try again");   
}
Subir Kumar Sao
  • 8,171
  • 3
  • 26
  • 47