JQuery error option in $.ajax utility

前端 未结 5 512
感动是毒
感动是毒 2020-12-04 10:18

The documentation indicates that the error: option function will make available: XHR instance, a status message string (in this case always error) and an optional exception

相关标签:
5条回答
  • 2020-12-04 10:46

    Are you sure that response is correct? Parse error mean that there is sth wrong with data being evaluted in line var t = eval( "(" + request + ")" ) ;

    0 讨论(0)
  • 2020-12-04 10:48

    The second argument that is passed to your error function will either be the string "timeout" "parserror" "error" or "notmodified". The third will be the exception object. This object can be helpful for debugging.

    0 讨论(0)
  • 2020-12-04 10:55

    I find the request more useful than the error.

    error:function(xhr,err){
        alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
        alert("responseText: "+xhr.responseText);
    }

    xhr is XmlHttpRequest.
    readyState values are 1:loading, 2:loaded, 3:interactive, 4:complete.
    status is the HTTP status number, i.e. 404: not found, 500: server error, 200: ok.
    responseText is the response from the server - this could be text or JSON from the web service, or HTML from the web server.

    0 讨论(0)
  • 2020-12-04 10:58

    Looking at the jQuery source code, there are four returned statuses, in additon to success:

    • timeout - when your specified timeout is exceeded
    • error - http error, like 404
    • notmodified - when requested resource was not modified since last request
    • parsererror - when an xml/json response is bad
    0 讨论(0)
  • 2020-12-04 11:03

    This is an aside, but I think there's a bug in the code you submitted. The line:

     if (error = "timeout") {
    

    should have more equals signs in it:

     if (error == "timeout") {
    
    0 讨论(0)
提交回复
热议问题