From 61f812b7e7b88dd6e0078c241e4c88905ea51562 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski?= Date: Mon, 30 Mar 2015 20:00:38 +0200 Subject: [PATCH] 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 --- src/ajax/xhr.js | 32 ++++++++++++------ test/integration/gh-1684-ajax.html | 52 ++++++++++++++++++++++++++++++ test/unit/ajax.js | 6 ++-- 3 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 test/integration/gh-1684-ajax.html diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 9c204a851..c563992f9 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -11,17 +11,31 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ? function() { // XHR cannot access local files, always use ActiveX for that case - return !this.isLocal && + if ( this.isLocal ) { + return createActiveXHR(); + } + + // Support: IE 10-11 + // IE seems to error on cross-domain PATCH requests when ActiveX XHR + // is used. In IE 9+ always use the native XHR. + // Note: this condition won't catch Spartan as it doesn't define + // document.documentMode but it also doesn't have ActiveX so it won't + // reach this code. + if ( document.documentMode > 8 ) { + return createStandardXHR(); + } - // Support: IE<9 - // oldIE XHR does not support non-RFC2616 methods (#13240) - // See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx - // and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9 - // Although this check for six methods instead of eight - // since IE also does not support "trace" and "connect" - /^(get|post|head|put|delete|options)$/i.test( this.type ) && + // Support: IE<9 + // oldIE XHR does not support non-RFC2616 methods (#13240) + // See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx + // and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9 + // Although this check for six methods instead of eight + // since IE also does not support "trace" and "connect" + if ( /^(get|post|head|put|delete|options)$/i.test( this.type ) ) { + return createActiveXHR(); + } - createStandardXHR() || createActiveXHR(); + return createStandardXHR(); } : // For all other browsers, use the standard XMLHttpRequest object createStandardXHR; diff --git a/test/integration/gh-1684-ajax.html b/test/integration/gh-1684-ajax.html new file mode 100644 index 000000000..55e31d7fe --- /dev/null +++ b/test/integration/gh-1684-ajax.html @@ -0,0 +1,52 @@ + + + + + + Test for gh-1684 + + + + +
+
+ + + + diff --git a/test/unit/ajax.js b/test/unit/ajax.js index f030b48fc..1233f14ce 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1578,8 +1578,10 @@ module( "ajax", { } } ); - // BrowserStack PATCH support sometimes breaks so on TestSwarm run the test in IE8 only. - if ( location.search.indexOf( "swarmURL=" ) === -1 || document.documentMode < 9 ) { + // BrowserStack PATCH support sometimes breaks so on TestSwarm run the test in IE only. + // Unfortunately, all IE versions gets special treatment in request object creation + // so we need to test in all supported IE versions to be sure. + if ( location.search.indexOf( "swarmURL=" ) === -1 || document.documentMode ) { ajaxTest( "#13240 - jQuery.ajax() - support non-RFC2616 methods", 1, { url: "data/echoQuery.php", method: "PATCH", -- 2.39.5