Why does JQuery/browsers call a network failure ajax ‘success’?

When you make an $.ajax request in JQuery, you can have a ‘success’ and ‘error’ callback.

Except if the remote URL is completely unreachable (for instance, because the app it points at is down), for some reason that still counts as ‘success’.  You can still recognize it by the xhr.status == 0. But pretty much every single time I write $.ajax, I need to put a check in my success handler for this, and treat it as error if so.

Why the heck are things this way?  It might not be jQueries fault, it might be browsers implementation of XHR.  But then why the heck do they do that?  And while you can find some people explaining this situation by googling, I can’t find any explanation of why things came to be this way. And I can’t find as much complaining about it as I’d expect — is this for some reason not as big an inconvenience for everyone else as for me, and if so why?

I wonder if jQuery at least has ever considered intercepting and normalizing this behavior, so on xhr.status=0 network error, it is not considered ‘success’ by jquery $.ajax and it’s descendents.

This entry was posted in General. Bookmark the permalink.

One Response to Why does JQuery/browsers call a network failure ajax ‘success’?

  1. You should try asking this question on StackOverflow, and see what answers you get.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s