Skip to content

Commit 873c284

Browse files
committed
Make sure we have a fallback when XMLHttpRequest is manually disabled. Fixes #6298.
1 parent 0368606 commit 873c284

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/ajax.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,10 @@ jQuery.extend({
180180
password: null,
181181
traditional: false,
182182
*/
183-
// Create the request object; Microsoft failed to properly
184-
// implement the XMLHttpRequest in IE7 (can't request local files),
185-
// so we use the ActiveXObject when it is available
186183
// This function can be overriden by calling jQuery.ajaxSetup
187-
xhr: window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ?
188-
function() {
189-
return new window.XMLHttpRequest();
190-
} :
191-
function() {
192-
try {
193-
return new window.ActiveXObject("Microsoft.XMLHTTP");
194-
} catch(e) {}
195-
},
184+
xhr: function() {
185+
return new window.XMLHttpRequest();
186+
},
196187
accepts: {
197188
xml: "application/xml, text/xml",
198189
html: "text/html",
@@ -695,6 +686,27 @@ jQuery.extend( jQuery.ajax, {
695686

696687
});
697688

689+
/*
690+
* Create the request object; Microsoft failed to properly
691+
* implement the XMLHttpRequest in IE7 (can't request local files),
692+
* so we use the ActiveXObject when it is available
693+
* Additionally XMLHttpRequest can be disabled in IE7/IE8 so
694+
* we need a fallback.
695+
*/
696+
if ( window.ActiveXObject ) {
697+
jQuery.ajaxSettings.xhr = function() {
698+
if ( window.location.protocol !== "file:" ) {
699+
try {
700+
return new window.XMLHttpRequest();
701+
} catch(e) {}
702+
}
703+
704+
try {
705+
return new window.ActiveXObject("Microsoft.XMLHTTP");
706+
} catch(e) {}
707+
};
708+
}
709+
698710
// Does this browser support XHR requests?
699711
jQuery.support.ajax = !!jQuery.ajaxSettings.xhr();
700712

0 commit comments

Comments
 (0)