dsf6778 2012-12-28 14:52
浏览 28
已采纳

跟踪ajax错误并提醒它

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.

  • 写回答

2条回答 默认 最新

  • dplm47571 2012-12-28 14:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?