jQuery: The Write Less, Do More JavaScript Library

ajax call results in error event triggered with status="error", XmlHttpRequest.status = 0

View: New views
1 Messages — Rating Filter:   Alert me  

ajax call results in error event triggered with status="error", XmlHttpRequest.status = 0

by Matt Brown-19 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One of the pages in our web application polls the server approximately
every 10 seconds for new data, using jQuery's ajax() method. We
normally have a few hundred users viewing this page simultaneously, so
our server receives several requests per second. The load is not any
sort of problem.

For some small percentage of our visitors, the jQuery ajax() call
ocassionally triggers it's error event. Most of these error events are
obvious errors (such as a timeout when visitors are having network
issues), but a small subset of these I'm having a lot of trouble
finding the cause of.

We are wiring up a global error listener like so

$.ajaxSetup({
    timeout: oursettings.timeout,
    error: function(xhr, status, e){
         // error handling goes here
    }
});


Occasionally our error-handling is hit with a status (which is set by
jQuery) of "error". When we examine the xhr object, it has a status
(which should be the HTTP Response code) of 0.

According to the XmlHttpRequest spec, it sounds like the XHR object
will be put in the DONE state (readystate = 4) with a status of 0 when
"the error flag" is set to true (which the spec states can happen due
to "some type of network error or abortion". http://www.w3.org/TR/XMLHttpRequest/#error-flag

I'd just like to confirm if this scenario is truly caused (only) by
network errors?

Is there any other reason why the error handler would be hit with a
(jQuery) status of "error" and a XHR status of 0 besides network error?