Skip to content

Commit

Permalink
Simplified some of the logic for handling the ajax aborts, making sur…
Browse files Browse the repository at this point in the history
…e that ajaxStop isn't called twice.
  • Loading branch information
jeresig committed Jan 12, 2010
1 parent d60b197 commit dd45c32
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/ajax.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -390,18 +390,19 @@ jQuery.extend({


// Wait for a response to come back // Wait for a response to come back
var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) { var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
// The request was aborted, clear the interval and decrement jQuery.active // The request was aborted
if ( !xhr || xhr.readyState === 0 ) { if ( !xhr || xhr.readyState === 0 ) {
// Opera doesn't call onreadystatechange before this point
// so we simulate the call
if ( !requestDone ) {
complete();
}

requestDone = true; requestDone = true;
if ( xhr ) { if ( xhr ) {
xhr.onreadystatechange = jQuery.noop; xhr.onreadystatechange = jQuery.noop;
} }


// 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
} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) { } else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
requestDone = true; requestDone = true;
Expand Down Expand Up @@ -456,15 +457,11 @@ jQuery.extend({
xhr.abort = function() { xhr.abort = function() {
oldAbort.call( xhr ); oldAbort.call( xhr );


if ( !requestDone ) {
complete();
}

if ( xhr ) { if ( xhr ) {
xhr.onreadystatechange = null; xhr.readyState = 0;
} }


requestDone = true; onreadystatechange();
}; };
} catch(e) { } } catch(e) { }


Expand Down

0 comments on commit dd45c32

Please sign in to comment.