I've used jQuery's ajaxSend and ajaxStop to show a spinner whenever ajax requests are active. It works except when some of my plugins abort their ajax requests, ajaxStop does not trigger and will not trigger until after the page is refreshed. It seems like the aborted request still counts to jQuery. Can I make ajaxStop trigger or is there a better way?
Well I figured out a way that I quite like. Patch the XMLHttpRequest abort method so that it will decrease jQuery's ajax counter and trigger the handler if it's the last request. Not sure yet how well it will work across browsers.
var old_abort = XMLHttpRequest.prototype.abort;
XMLHttpRequest.prototype.abort = function(){
jQuery.proxy(old_abort, this)();
if ( jQuery.active-- === 1 )
jQuery.event.trigger( "ajaxStop" );
};