]> source.dussan.org Git - jquery.git/commitdiff
Fix #14379: AJAX requests on unload
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 28 Oct 2013 21:40:13 +0000 (17:40 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Mon, 4 Nov 2013 14:41:19 +0000 (09:41 -0500)
(cherry picked from commit f9d41ac641dcb5a93ba8a9027476b160d8f41111)

Conflicts:

src/ajax/xhr.js

test/data/ajax/onunload.html [new file with mode: 0644]
test/unit/ajax.js

diff --git a/test/data/ajax/onunload.html b/test/data/ajax/onunload.html
new file mode 100644 (file)
index 0000000..2c629f6
--- /dev/null
@@ -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>
index 22fed363c8978579cba723f2c14604bb7d6b1d01..fee2d8a04730fb3076f45ee570160d1f4a1e1763 100644 (file)
@@ -1565,6 +1565,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, {