Fixes #5955. Option crossDomain now forces ajax to consider a request as cross-domain...
[jquery.git] / test / unit / ajax.js
index 14f8928..8bfd4d3 100644 (file)
@@ -257,6 +257,29 @@ test("jQuery.ajax() - responseText on error", function() {
        });
 });
 
+test(".ajax() - retry with jQuery.ajax( this )", function() {
+
+       expect( 1 );
+
+       stop();
+
+       var firstTime = 1;
+
+       jQuery.ajax({
+               url: url("data/errorWithText.php"),
+               error: function() {
+                       if ( firstTime ) {
+                               firstTime = 0;
+                               jQuery.ajax( this );
+                       } else {
+                               ok( true , "Test retrying with jQuery.ajax(this) works" );
+                               start();
+                       }
+               }
+       })
+
+});
+
 test(".ajax() - headers" , function() {
 
        expect( 2 );
@@ -360,14 +383,15 @@ test(".ajax() - hash", function() {
 
 test("jQuery ajax - cross-domain detection", function() {
 
-       expect( 3 );
+       expect( 4 );
 
        var loc = document.location,
                otherPort = loc.port === 666 ? 667 : 666,
                otherProtocol = loc.protocol === "http:" ? "https:" : "http:",
                protocolFlag,
                hostFlag,
-               portFlag;
+               portFlag,
+               forcedFlag;
 
        if ( jQuery.ajax({
                url: otherProtocol + "//" + loc.host,
@@ -408,6 +432,20 @@ test("jQuery ajax - cross-domain detection", function() {
                }
        }
 
+       if ( jQuery.ajax({
+               url: loc.protocol + "//" + loc.host,
+               crossDomain: true,
+               beforeSend: function( _ , s ) {
+                       forcedFlag = 1;
+                       ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" );
+                       return false;
+               }
+       }) === false ) {
+               if ( ! forcedFlag ) {
+                       ok( ! jQuery.support.cors , "Test forced crossDomain is detected as cross-domain (no transport)" );
+               }
+       }
+
 });
 
 test(".ajax() - 304", function() {