From: Richard Gibson Date: Mon, 28 Oct 2013 21:40:13 +0000 (-0400) Subject: Fix #14379: AJAX requests on unload X-Git-Tag: 2.1.0-beta2~43 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f9d41ac6;p=jquery.git Fix #14379: AJAX requests on unload --- diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 8e6696b0d..5dbfc646f 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -18,18 +18,16 @@ var xhrSupported = jQuery.ajaxSettings.xhr(), // #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 = {}; +// Support: IE9 +// Open requests must be manually aborted on unload (#5280) if ( window.ActiveXObject ) { jQuery( window ).on( "unload", function() { for ( var key in xhrCallbacks ) { xhrCallbacks[ key ](); } - xhrCallbacks = undefined; }); } diff --git a/test/data/ajax/onunload.html b/test/data/ajax/onunload.html new file mode 100644 index 000000000..2c629f67d --- /dev/null +++ b/test/data/ajax/onunload.html @@ -0,0 +1,30 @@ + + + + + onunload ajax requests (#14379) + + + + + + + diff --git a/test/unit/ajax.js b/test/unit/ajax.js index da1f2ce38..d446d64f1 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1522,6 +1522,11 @@ module( "ajax", { } } ); + testIframeWithCallback( "#14379 - jQuery.ajax() on unload", "ajax/onunload.html", function( status ) { + expect( 1 ); + strictEqual( status, "success", "Request completed" ); + }); + //----------- jQuery.ajaxPrefilter() ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, {