]> source.dussan.org Git - jquery.git/commitdiff
Moved unload abort code so that the event is only bound if the xhr transport is used...
authorjaubourg <j@ubourg.net>
Sun, 9 Jan 2011 21:20:58 +0000 (22:20 +0100)
committerjaubourg <j@ubourg.net>
Sun, 9 Jan 2011 21:20:58 +0000 (22:20 +0100)
src/ajax/xhr.js

index a2ec4a4c5b500d0e76e2bac35e1b9da4f3a69a84..26e91ce790ca1a057553c2f3fca292588861d421 100644 (file)
@@ -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 );