diff options
author | jaubourg <j@ubourg.net> | 2011-01-09 22:20:58 +0100 |
---|---|---|
committer | jaubourg <j@ubourg.net> | 2011-01-09 22:20:58 +0100 |
commit | 1d1d4fe112c49cbd704d880b27cc646f2bfe1737 (patch) | |
tree | 6e7480d666822fe87fc1188384d9884183512cda /src/ajax/xhr.js | |
parent | 8c8bd3bf6ac982f98c1b89b0af74a1fd2d07e360 (diff) | |
download | jquery-1d1d4fe112c49cbd704d880b27cc646f2bfe1737.tar.gz jquery-1d1d4fe112c49cbd704d880b27cc646f2bfe1737.zip |
Moved unload abort code so that the event is only bound if the xhr transport is used. Fixes #5280.
Diffstat (limited to 'src/ajax/xhr.js')
-rw-r--r-- | src/ajax/xhr.js | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index a2ec4a4c5..26e91ce79 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -10,7 +10,7 @@ var // Next fake timer id xhrPool = [], // #5280: see end of file - xhrUnloadAbortMarker = []; + xhrUnloadAbortMarker; jQuery.ajax.transport( function( s , determineDataType ) { @@ -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; @@ -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 ); |