🌐 AI搜索 & 代理 主页
Skip to content

Commit 9dd5d95

Browse files
committed
Ajax: Use the native XHR for all non-local requests in IE9+
IE throws an error on cross-domain PATCH requests if issued via the ActiveX interface. This commit switches the logic to use the native XHR in all non-local requests. Fixes gh-1684 Closes gh-2183
1 parent 35295f1 commit 9dd5d95

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/ajax/xhr.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,31 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ?
1111
function() {
1212

1313
// XHR cannot access local files, always use ActiveX for that case
14-
return !this.isLocal &&
14+
if ( this.isLocal ) {
15+
return createActiveXHR();
16+
}
17+
18+
// Support: IE 10-11
19+
// IE seems to error on cross-domain PATCH requests when ActiveX XHR
20+
// is used. In IE 9+ always use the native XHR.
21+
// Note: this condition won't catch Spartan as it doesn't define
22+
// document.documentMode but it also doesn't have ActiveX so it won't
23+
// reach this code.
24+
if ( document.documentMode > 8 ) {
25+
return createStandardXHR();
26+
}
1527

16-
// Support: IE<9
17-
// oldIE XHR does not support non-RFC2616 methods (#13240)
18-
// See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx
19-
// and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9
20-
// Although this check for six methods instead of eight
21-
// since IE also does not support "trace" and "connect"
22-
/^(get|post|head|put|delete|options)$/i.test( this.type ) &&
28+
// Support: IE<9
29+
// oldIE XHR does not support non-RFC2616 methods (#13240)
30+
// See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx
31+
// and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9
32+
// Although this check for six methods instead of eight
33+
// since IE also does not support "trace" and "connect"
34+
if ( /^(get|post|head|put|delete|options)$/i.test( this.type ) ) {
35+
return createActiveXHR();
36+
}
2337

24-
createStandardXHR() || createActiveXHR();
38+
return createStandardXHR();
2539
} :
2640
// For all other browsers, use the standard XMLHttpRequest object
2741
createStandardXHR;

test/unit/ajax.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ module( "ajax", {
15791579
} );
15801580

15811581
// BrowserStack PATCH support sometimes breaks so on TestSwarm run the test in IE8 only.
1582-
if ( location.search.indexOf( "swarmURL=" ) === -1 || document.documentMode < 9 ) {
1582+
if ( location.search.indexOf( "swarmURL=" ) === -1 || document.documentMode ) {
15831583
ajaxTest( "#13240 - jQuery.ajax() - support non-RFC2616 methods", 1, {
15841584
url: "data/echoQuery.php",
15851585
method: "PATCH",
@@ -1592,6 +1592,23 @@ module( "ajax", {
15921592
} );
15931593
}
15941594

1595+
// BrowserStack PATCH support sometimes breaks so on TestSwarm run the test in IE only.
1596+
// Unfortunately, all IE versions gets special treatment in request object creation
1597+
// so we need to test in all supported IE versions to be sure.
1598+
if ( ( location.search.indexOf( "swarmURL=" ) === -1 || document.documentMode ) &&
1599+
jQuery.support.cors ) {
1600+
ajaxTest( "gh-1684 - jQuery.ajax() - support cross-domain PATCH in IE10-11", 1, {
1601+
url: "http://httpbin.org/patch",
1602+
method: "PATCH",
1603+
success: function() {
1604+
ok( true, "success" );
1605+
},
1606+
error: function() {
1607+
ok( false, "error" );
1608+
}
1609+
} );
1610+
}
1611+
15951612
testIframeWithCallback( "#14379 - jQuery.ajax() on unload", "ajax/onunload.html", function( status ) {
15961613
expect( 1 );
15971614
strictEqual( status, "success", "Request completed" );

0 commit comments

Comments
 (0)