X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax%2Fxhr.js;h=26e91ce790ca1a057553c2f3fca292588861d421;hb=1d1d4fe112c49cbd704d880b27cc646f2bfe1737;hp=032668f68d7e60228208b3f974600a695b50a1df;hpb=98c6c4b2b0afb2754883fc39c5626da3219e81e0;p=jquery.git diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 032668f..26e91ce 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; @@ -137,15 +157,13 @@ jQuery.ajax.transport( function( s , determineDataType ) { status ); - // Guess response if needed & update datatype accordingly - if ( status >= 200 && status < 300 ) { - response = - determineDataType( - s, - xhr.getResponseHeader("content-type"), - xhr.responseText, - xhr.responseXML ); - } + // Guess response & update dataType accordingly + response = + determineDataType( + s, + xhr.getResponseHeader("content-type"), + xhr.responseText, + xhr.responseXML ); } // Call complete @@ -180,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 );