Fixes #5955. Option crossDomain now forces ajax to consider a request as cross-domain even when it is not. Useful for when servers issue redirects to cross-domain urls. Unit test added.
This commit is contained in:
parent
c55a76a23f
commit
5a5f67800b
2 changed files with 26 additions and 8 deletions
15
src/ajax.js
15
src/ajax.js
|
@ -520,12 +520,15 @@ jQuery.extend({
|
||||||
// Determine if a cross-domain request is in order
|
// Determine if a cross-domain request is in order
|
||||||
var parts = rurl.exec( s.url.toLowerCase() ),
|
var parts = rurl.exec( s.url.toLowerCase() ),
|
||||||
loc = location;
|
loc = location;
|
||||||
s.crossDomain = !!(
|
|
||||||
parts &&
|
if ( ! s.crossDomain ) {
|
||||||
( parts[ 1 ] && parts[ 1 ] != loc.protocol ||
|
s.crossDomain = !!(
|
||||||
parts[ 2 ] != loc.hostname ||
|
parts &&
|
||||||
( parts[ 3 ] || 80 ) != ( loc.port || 80 ) )
|
( parts[ 1 ] && parts[ 1 ] != loc.protocol ||
|
||||||
);
|
parts[ 2 ] != loc.hostname ||
|
||||||
|
( parts[ 3 ] || 80 ) != ( loc.port || 80 ) )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert data if not already a string
|
// Convert data if not already a string
|
||||||
if ( s.data && s.processData && typeof s.data != "string" ) {
|
if ( s.data && s.processData && typeof s.data != "string" ) {
|
||||||
|
|
|
@ -383,14 +383,15 @@ test(".ajax() - hash", function() {
|
||||||
|
|
||||||
test("jQuery ajax - cross-domain detection", function() {
|
test("jQuery ajax - cross-domain detection", function() {
|
||||||
|
|
||||||
expect( 3 );
|
expect( 4 );
|
||||||
|
|
||||||
var loc = document.location,
|
var loc = document.location,
|
||||||
otherPort = loc.port === 666 ? 667 : 666,
|
otherPort = loc.port === 666 ? 667 : 666,
|
||||||
otherProtocol = loc.protocol === "http:" ? "https:" : "http:",
|
otherProtocol = loc.protocol === "http:" ? "https:" : "http:",
|
||||||
protocolFlag,
|
protocolFlag,
|
||||||
hostFlag,
|
hostFlag,
|
||||||
portFlag;
|
portFlag,
|
||||||
|
forcedFlag;
|
||||||
|
|
||||||
if ( jQuery.ajax({
|
if ( jQuery.ajax({
|
||||||
url: otherProtocol + "//" + loc.host,
|
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() {
|
test(".ajax() - 304", function() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue