Skip to content
Permalink
Browse files

Fix #14379: AJAX requests on unload

  • Loading branch information...
gibson042 committed Oct 28, 2013
1 parent ebabb33 commit f9d41ac641dcb5a93ba8a9027476b160d8f41111
Showing with 37 additions and 4 deletions.
  1. +2 −4 src/ajax/xhr.js
  2. +30 −0 test/data/ajax/onunload.html
  3. +5 −0 test/unit/ajax.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;
});
}

@@ -0,0 +1,30 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>onunload ajax requests (#14379)</title>
<script src="../../jquery.js"></script>
</head>
<body>
<form id="navigate" action="about:blank"></form>
<script>
jQuery( window ).on( "unload", function() {
var ajaxStatus;
jQuery.ajax({
url: "../name.html",
async: false,
complete: function( xhr, status ) {
ajaxStatus = status;
}
});
parent.iframeCallback( ajaxStatus );
});
jQuery(function() {
setTimeout(function() {
document.getElementById( "navigate" ).submit();
}, 0 );
});
</script>
</body>
</html>
@@ -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, {

0 comments on commit f9d41ac

Please sign in to comment.
You can’t perform that action at this time.