@@ -11,8 +11,22 @@ var xhrSupported = jQuery.ajaxSettings.xhr(),
1111 // Support: IE9
1212 // #1450: sometimes IE returns 1223 when it should be 204
1313 1223 : 204
14- } ;
15-
14+ } ,
15+ // Support: IE9
16+ // We need to keep track of outbound xhr and abort them manually
17+ // because IE is not smart enough to do it all by itself
18+ xhrId = 0 ,
19+ xhrCallbacks = { } ;
20+
21+ if ( window . ActiveXObject ) {
22+ jQuery ( window ) . on ( "unload" , function ( ) {
23+ for ( var key in xhrCallbacks ) {
24+ xhrCallbacks [ key ] ( ) ;
25+ }
26+ xhrCallbacks = undefined ;
27+ } ) ;
28+ }
29+
1630jQuery . support . cors = ! ! xhrSupported && ( "withCredentials" in xhrSupported ) ;
1731jQuery . support . ajax = xhrSupported = ! ! xhrSupported ;
1832
@@ -22,7 +36,7 @@ jQuery.ajaxTransport(function( options ) {
2236 if ( jQuery . support . cors || xhrSupported && ! options . crossDomain ) {
2337 return {
2438 send : function ( headers , complete ) {
25- var i ,
39+ var i , id ,
2640 xhr = options . xhr ( ) ;
2741 xhr . open ( options . type , options . url , options . async , options . username , options . password ) ;
2842 // Apply custom fields if provided
@@ -51,6 +65,7 @@ jQuery.ajaxTransport(function( options ) {
5165 callback = function ( type ) {
5266 return function ( ) {
5367 if ( callback ) {
68+ delete xhrCallbacks [ id ] ;
5469 callback = xhr . onload = xhr . onerror = null ;
5570 if ( type === "abort" ) {
5671 xhr . abort ( ) ;
@@ -80,7 +95,7 @@ jQuery.ajaxTransport(function( options ) {
8095 xhr . onload = callback ( ) ;
8196 xhr . onerror = callback ( "error" ) ;
8297 // Create the abort callback
83- callback = callback ( "abort" ) ;
98+ callback = xhrCallbacks [ ( id = xhrId ++ ) ] = callback ( "abort" ) ;
8499 // Do send the request
85100 // This may raise an exception which is actually
86101 // handled in jQuery.ajax (so no try/catch here)
0 commit comments