]> source.dussan.org Git - jquery.git/commitdiff
Fixes #5955. Option crossDomain now forces ajax to consider a request as cross-domain...
authorjaubourg <j@ubourg.net>
Sun, 9 Jan 2011 15:50:13 +0000 (16:50 +0100)
committerjaubourg <j@ubourg.net>
Sun, 9 Jan 2011 15:50:13 +0000 (16:50 +0100)
src/ajax.js
test/unit/ajax.js

index e910aa56f73d78c92e347450de6e3a867af68d6b..eae20e459117c9eac8173ad1b3d780ad00ff5f48 100644 (file)
@@ -520,12 +520,15 @@ jQuery.extend({
                // Determine if a cross-domain request is in order
                var parts = rurl.exec( s.url.toLowerCase() ),
                        loc = location;
-               s.crossDomain = !!(
-                               parts &&
-                               ( parts[ 1 ] && parts[ 1 ] != loc.protocol ||
-                                       parts[ 2 ] != loc.hostname ||
-                                       ( parts[ 3 ] || 80 ) != ( loc.port || 80 ) )
-               );
+
+               if ( ! s.crossDomain ) {
+                       s.crossDomain = !!(
+                                       parts &&
+                                       ( parts[ 1 ] && parts[ 1 ] != loc.protocol ||
+                                               parts[ 2 ] != loc.hostname ||
+                                               ( parts[ 3 ] || 80 ) != ( loc.port || 80 ) )
+                       );
+               }
 
                // Convert data if not already a string
                if ( s.data && s.processData && typeof s.data != "string" ) {
index 4c8c5009be66ffb4fbd74e861bc13e1ec3a894bf..8bfd4d3e05fbd661e5df0dc2f2a297cbe1909926 100644 (file)
@@ -383,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,
@@ -431,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() {