Landing fixes for tickets #2935 and #2688 (Aborting ajax doesn't stop the setInterval, ajaxStop event isn't getting triggered).

This commit is contained in:
John Resig 2008-11-14 04:16:00 +00:00
parent 464535e096
commit 0aa8d40cdf

View file

@ -308,10 +308,11 @@ jQuery.extend({
s.accepts._default ); s.accepts._default );
} catch(e){} } catch(e){}
// Allow custom headers/mimetypes // Allow custom headers/mimetypes and early abort
if ( s.beforeSend && s.beforeSend(xhr, s) === false ) { if ( s.beforeSend && s.beforeSend(xhr, s) === false ) {
// cleanup active request counter // Handle the global AJAX counter
s.global && jQuery.active--; if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
// close opended socket // close opended socket
xhr.abort(); xhr.abort();
return false; return false;
@ -322,8 +323,18 @@ jQuery.extend({
// Wait for a response to come back // Wait for a response to come back
var onreadystatechange = function(isTimeout){ var onreadystatechange = function(isTimeout){
// The request was aborted, clear the interval and decrement jQuery.active
if (xhr.readyState == 0) {
if (ival) {
// clear poll interval
clearInterval(ival);
ival = null;
// Handle the global AJAX counter
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
}
// The transfer is complete and the data is available, or the request timed out // The transfer is complete and the data is available, or the request timed out
if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) { } else if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) {
requestDone = true; requestDone = true;
// clear poll interval // clear poll interval