|
1 | 1 | (function( jQuery ) {
|
2 | 2 |
|
3 |
| -var // #5280: next active xhr id and list of active xhrs' callbacks |
4 |
| - xhrId = jQuery.now(), |
5 |
| - xhrCallbacks, |
6 |
| - |
7 |
| - // XHR used to determine supports properties |
8 |
| - testXHR; |
9 |
| - |
10 |
| -// #5280: Internet Explorer will keep connections alive if we don't abort on unload |
11 |
| -function xhrOnUnloadAbort() { |
12 |
| - jQuery( window ).unload(function() { |
| 3 | +var // #5280: Internet Explorer will keep connections alive if we don't abort on unload |
| 4 | + xhrOnUnloadAbort = window.ActiveXObject ? function() { |
13 | 5 | // Abort all pending requests
|
14 | 6 | for ( var key in xhrCallbacks ) {
|
15 | 7 | xhrCallbacks[ key ]( 0, 1 );
|
16 | 8 | }
|
17 |
| - }); |
18 |
| -} |
| 9 | + } : false, |
| 10 | + xhrId = 0, |
| 11 | + xhrCallbacks; |
19 | 12 |
|
20 | 13 | // Functions to create xhrs
|
21 | 14 | function createStandardXHR() {
|
@@ -45,15 +38,13 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject ?
|
45 | 38 | // For all other browsers, use the standard XMLHttpRequest object
|
46 | 39 | createStandardXHR;
|
47 | 40 |
|
48 |
| -// Test if we can create an xhr object |
49 |
| -testXHR = jQuery.ajaxSettings.xhr(); |
50 |
| -jQuery.support.ajax = !!testXHR; |
51 |
| - |
52 |
| -// Does this browser support crossDomain XHR requests |
53 |
| -jQuery.support.cors = testXHR && ( "withCredentials" in testXHR ); |
54 |
| - |
55 |
| -// No need for the temporary xhr anymore |
56 |
| -testXHR = undefined; |
| 41 | +// Determine support properties |
| 42 | +(function( xhr ) { |
| 43 | + jQuery.extend( jQuery.support, { |
| 44 | + ajax: !!xhr, |
| 45 | + cors: !!xhr && ( "withCredentials" in xhr ) |
| 46 | + }); |
| 47 | +})( jQuery.ajaxSettings.xhr() ); |
57 | 48 |
|
58 | 49 | // Create transport if the browser can provide an xhr
|
59 | 50 | if ( jQuery.support.ajax ) {
|
@@ -136,7 +127,9 @@ if ( jQuery.support.ajax ) {
|
136 | 127 | // Do not keep as active anymore
|
137 | 128 | if ( handle ) {
|
138 | 129 | xhr.onreadystatechange = jQuery.noop;
|
139 |
| - delete xhrCallbacks[ handle ]; |
| 130 | + if ( xhrOnUnloadAbort ) { |
| 131 | + delete xhrCallbacks[ handle ]; |
| 132 | + } |
140 | 133 | }
|
141 | 134 |
|
142 | 135 | // If it's an abort
|
@@ -197,15 +190,18 @@ if ( jQuery.support.ajax ) {
|
197 | 190 | if ( !s.async || xhr.readyState === 4 ) {
|
198 | 191 | callback();
|
199 | 192 | } else {
|
200 |
| - // Create the active xhrs callbacks list if needed |
201 |
| - // and attach the unload handler |
202 |
| - if ( !xhrCallbacks ) { |
203 |
| - xhrCallbacks = {}; |
204 |
| - xhrOnUnloadAbort(); |
| 193 | + handle = ++xhrId; |
| 194 | + if ( xhrOnUnloadAbort ) { |
| 195 | + // Create the active xhrs callbacks list if needed |
| 196 | + // and attach the unload handler |
| 197 | + if ( !xhrCallbacks ) { |
| 198 | + xhrCallbacks = {}; |
| 199 | + jQuery( window ).unload( xhrOnUnloadAbort ); |
| 200 | + } |
| 201 | + // Add to list of active xhrs callbacks |
| 202 | + xhrCallbacks[ handle ] = callback; |
205 | 203 | }
|
206 |
| - // Add to list of active xhrs callbacks |
207 |
| - handle = xhrId++; |
208 |
| - xhr.onreadystatechange = xhrCallbacks[ handle ] = callback; |
| 204 | + xhr.onreadystatechange = callback; |
209 | 205 | }
|
210 | 206 | },
|
211 | 207 |
|
|
0 commit comments