Makes sure no unload handler is bound when not in IE. Also simplifies the whole "on unload abort" code. Also avoids the declaration of yet another variables in the jQuery main closure for the temporary XHR used to assess support properties.
This commit is contained in:
parent
60cfab3d19
commit
a28eadff48
|
@ -1,21 +1,14 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var // #5280: next active xhr id and list of active xhrs' callbacks
|
||||
xhrId = jQuery.now(),
|
||||
xhrCallbacks,
|
||||
|
||||
// XHR used to determine supports properties
|
||||
testXHR;
|
||||
|
||||
// #5280: Internet Explorer will keep connections alive if we don't abort on unload
|
||||
function xhrOnUnloadAbort() {
|
||||
jQuery( window ).unload(function() {
|
||||
var // #5280: Internet Explorer will keep connections alive if we don't abort on unload
|
||||
xhrOnUnloadAbort = window.ActiveXObject ? function() {
|
||||
// Abort all pending requests
|
||||
for ( var key in xhrCallbacks ) {
|
||||
xhrCallbacks[ key ]( 0, 1 );
|
||||
}
|
||||
});
|
||||
}
|
||||
} : false,
|
||||
xhrId = 0,
|
||||
xhrCallbacks;
|
||||
|
||||
// Functions to create xhrs
|
||||
function createStandardXHR() {
|
||||
|
@ -45,15 +38,13 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject ?
|
|||
// For all other browsers, use the standard XMLHttpRequest object
|
||||
createStandardXHR;
|
||||
|
||||
// Test if we can create an xhr object
|
||||
testXHR = jQuery.ajaxSettings.xhr();
|
||||
jQuery.support.ajax = !!testXHR;
|
||||
|
||||
// Does this browser support crossDomain XHR requests
|
||||
jQuery.support.cors = testXHR && ( "withCredentials" in testXHR );
|
||||
|
||||
// No need for the temporary xhr anymore
|
||||
testXHR = undefined;
|
||||
// Determine support properties
|
||||
(function( xhr ) {
|
||||
jQuery.extend( jQuery.support, {
|
||||
ajax: !!xhr,
|
||||
cors: !!xhr && ( "withCredentials" in xhr )
|
||||
});
|
||||
})( jQuery.ajaxSettings.xhr() );
|
||||
|
||||
// Create transport if the browser can provide an xhr
|
||||
if ( jQuery.support.ajax ) {
|
||||
|
@ -136,8 +127,10 @@ if ( jQuery.support.ajax ) {
|
|||
// Do not keep as active anymore
|
||||
if ( handle ) {
|
||||
xhr.onreadystatechange = jQuery.noop;
|
||||
if ( xhrOnUnloadAbort ) {
|
||||
delete xhrCallbacks[ handle ];
|
||||
}
|
||||
}
|
||||
|
||||
// If it's an abort
|
||||
if ( isAbort ) {
|
||||
|
@ -197,15 +190,18 @@ if ( jQuery.support.ajax ) {
|
|||
if ( !s.async || xhr.readyState === 4 ) {
|
||||
callback();
|
||||
} else {
|
||||
handle = ++xhrId;
|
||||
if ( xhrOnUnloadAbort ) {
|
||||
// Create the active xhrs callbacks list if needed
|
||||
// and attach the unload handler
|
||||
if ( !xhrCallbacks ) {
|
||||
xhrCallbacks = {};
|
||||
xhrOnUnloadAbort();
|
||||
jQuery( window ).unload( xhrOnUnloadAbort );
|
||||
}
|
||||
// Add to list of active xhrs callbacks
|
||||
handle = xhrId++;
|
||||
xhr.onreadystatechange = xhrCallbacks[ handle ] = callback;
|
||||
xhrCallbacks[ handle ] = callback;
|
||||
}
|
||||
xhr.onreadystatechange = callback;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue