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 object returned from the XHR instance (Book: JQuery in Action)
Using the following (in the $.ajax call) I was able to determine I had a "parsererror" and a "timeout" (since I added the timeout: option) error
error: function(request, error){}
What are other things you evaluate in the error option? do you include the optional exception object?
EDIT: one of the answers indicates all the return errors...learning more about what is of value (for debugging) in the XHR instance and exception object would be helpful
This is a complete $.ajax call:
$.ajax({ type: "post", url: "http://myServer/cgi-bin/broker" , dataType: "text", data: { '_service' : 'myService', '_program' : 'myProgram', 'start' : start, 'end' : end }, beforeSend: function() { $("#loading").removeClass("hide"); }, timeout: 5000, error: function(request,error) { $("#loading").addClass("hide"); if (error == "timeout") { $("#error").append("The request timed out, please resubmit"); } else { $("#error").append("ERROR: " + error); } }, success: function(request) { $("#loading").addClass("hide"); var t = eval( "(" + request + ")" ) ; } // End success }); // End ajax method
Thanks for the input
Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all handlers that have been registered with the . ajaxError() method are executed at this time. Note: This handler is not called for cross-domain script and cross-domain JSONP requests.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With