Experiences on the Front Lines of User Interfaces and Web Development

Mozilla Firefox exception when doing ajax call

If you have ever got the following exception in Firefox
uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://localhost:3000/ajax2.html :: anonymous :: line 21" data: no]

or if you get this in Chrome:
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11

Then you might be running into a bug where accessing "status" on the complete handler when the ajax request timed out causes a browser exception.  It is easy to reproduce using jQuery 1.3.2 (and 1.4.2) if you simply alert the xhr status after a timeout error.

Javascript code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript">

<script type="text/javascript">
jQuery.ajax( {
url: "/sessions/new",
timeout: 1,
complete: function( xhr ) { alert( xhr.status ); }
} );

I could not find a jQuery ticket or any bug reports. If you know of one, please post it in the comments!

The workaround is to simply check the text status provided by jQuery before trying to access xhr.status (and perhaps this is the only supported way to safely check the ajax status):
complete: function( xhr, text_status )
if ( text_status == 'timeout' )
alert( 'TIMED OUT' );
alert( xhr.status );
comments powered by Disqus