aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax/xhr.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2013-01-06 01:34:24 +0100
committerDave Methvin <dave.methvin@gmail.com>2013-01-07 10:34:14 -0500
commit62acda819f9b6fba9263d0b613e15285807b23a7 (patch)
treebfacb6fdeadd98eb2a6ff99c852a663132f1753c /src/ajax/xhr.js
parentf6df0301c81fca4b52eb2667f33a1469f2cac41d (diff)
downloadjquery-62acda819f9b6fba9263d0b613e15285807b23a7.tar.gz
jquery-62acda819f9b6fba9263d0b613e15285807b23a7.zip
Adds the abort on unload trick back in since IE9 still exhibits the bug
Diffstat (limited to 'src/ajax/xhr.js')
-rw-r--r--src/ajax/xhr.js23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js
index 72703a0b1..3a9c9e968 100644
--- a/src/ajax/xhr.js
+++ b/src/ajax/xhr.js
@@ -11,8 +11,22 @@ var xhrSupported = jQuery.ajaxSettings.xhr(),
// Support: IE9
// #1450: sometimes IE returns 1223 when it should be 204
1223: 204
- };
-
+ },
+ // Support: IE9
+ // We need to keep track of outbound xhr and abort them manually
+ // because IE is not smart enough to do it all by itself
+ xhrId = 0,
+ xhrCallbacks = {};
+
+if ( window.ActiveXObject ) {
+ jQuery( window ).on( "unload", function() {
+ for( var key in xhrCallbacks ) {
+ xhrCallbacks[ key ]();
+ }
+ xhrCallbacks = undefined;
+ });
+}
+
jQuery.support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
jQuery.support.ajax = xhrSupported = !!xhrSupported;
@@ -22,7 +36,7 @@ jQuery.ajaxTransport(function( options ) {
if ( jQuery.support.cors || xhrSupported && !options.crossDomain ) {
return {
send: function( headers, complete ) {
- var i,
+ var i, id,
xhr = options.xhr();
xhr.open( options.type, options.url, options.async, options.username, options.password );
// Apply custom fields if provided
@@ -51,6 +65,7 @@ jQuery.ajaxTransport(function( options ) {
callback = function( type ) {
return function() {
if ( callback ) {
+ delete xhrCallbacks[ id ];
callback = xhr.onload = xhr.onerror = null;
if ( type === "abort" ) {
xhr.abort();
@@ -80,7 +95,7 @@ jQuery.ajaxTransport(function( options ) {
xhr.onload = callback();
xhr.onerror = callback("error");
// Create the abort callback
- callback = callback("abort");
+ callback = xhrCallbacks[( id = xhrId++ )] = callback("abort");
// Do send the request
// This may raise an exception which is actually
// handled in jQuery.ajax (so no try/catch here)