JQuery error option in $.ajax utility JQuery error option in $.ajax utility jquery jquery

JQuery error option in $.ajax utility


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.


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

  • timeout - when your specifiedtimeout is exceeded
  • error - http error, like 404
  • notmodified - when requestedresource was not modified since lastrequest
  • parsererror - when an xml/json response isbad


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") {