Skip to content

Commit

Permalink
Moved unload abort code so that the event is only bound if the xhr tr…
Browse files Browse the repository at this point in the history
…ansport is used. Fixes #5280.
  • Loading branch information
jaubourg committed Jan 9, 2011
1 parent 8c8bd3b commit 1d1d4fe
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/ajax/xhr.js
Expand Up @@ -10,7 +10,7 @@ var // Next fake timer id
xhrPool = [],

// #5280: see end of file
xhrUnloadAbortMarker = [];
xhrUnloadAbortMarker;


jQuery.ajax.transport( function( s , determineDataType ) {
Expand All @@ -24,6 +24,26 @@ jQuery.ajax.transport( function( s , determineDataType ) {

send: function(headers, complete) {

// #5280: we need to abort on unload or IE will keep connections alive
if ( ! xhrUnloadAbortMarker ) {

xhrUnloadAbortMarker = [];

jQuery(window).bind( "unload" , function() {

// Abort all pending requests
jQuery.each(xhrs, function(_, xhr) {
if ( xhr.onreadystatechange ) {
xhr.onreadystatechange( xhrUnloadAbortMarker );
}
});

// Reset polling structure to be safe
xhrs = {};

});
}

var xhr = xhrPool.pop() || s.xhr(),
handle;

Expand Down Expand Up @@ -178,19 +198,4 @@ jQuery.ajax.transport( function( s , determineDataType ) {
}
});

// #5280: we need to abort on unload or IE will keep connections alive
jQuery(window).bind( "unload" , function() {

// Abort all pending requests
jQuery.each(xhrs, function(_, xhr) {
if ( xhr.onreadystatechange ) {
xhr.onreadystatechange( xhrUnloadAbortMarker );
}
});

// Resest polling structure to be safe
xhrs = {};

});

})( jQuery );

0 comments on commit 1d1d4fe

Please sign in to comment.