]> source.dussan.org Git - jquery.git/commitdiff
Make sure we have a fallback when XMLHttpRequest is manually disabled. Fixes #6298.
authorJohn Resig <jeresig@gmail.com>
Tue, 28 Sep 2010 17:12:33 +0000 (10:12 -0700)
committerJohn Resig <jeresig@gmail.com>
Tue, 28 Sep 2010 17:12:33 +0000 (10:12 -0700)
src/ajax.js

index 31efc566f0a9f236df071333f9842484972baa0a..e6154806808093afcd5e84df95a2ecde89b3ae23 100644 (file)
@@ -180,19 +180,10 @@ jQuery.extend({
                password: null,
                traditional: false,
                */
-               // Create the request object; Microsoft failed to properly
-               // implement the XMLHttpRequest in IE7 (can't request local files),
-               // so we use the ActiveXObject when it is available
                // This function can be overriden by calling jQuery.ajaxSetup
-               xhr: window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ?
-                       function() {
-                               return new window.XMLHttpRequest();
-                       } :
-                       function() {
-                               try {
-                                       return new window.ActiveXObject("Microsoft.XMLHTTP");
-                               } catch(e) {}
-                       },
+               xhr: function() {
+                       return new window.XMLHttpRequest();
+               },
                accepts: {
                        xml: "application/xml, text/xml",
                        html: "text/html",
@@ -695,6 +686,27 @@ jQuery.extend( jQuery.ajax, {
 
 });
 
+/*
+ * Create the request object; Microsoft failed to properly
+ * implement the XMLHttpRequest in IE7 (can't request local files),
+ * so we use the ActiveXObject when it is available
+ * Additionally XMLHttpRequest can be disabled in IE7/IE8 so
+ * we need a fallback.
+ */
+if ( window.ActiveXObject ) {
+       jQuery.ajaxSettings.xhr = function() {
+               if ( window.location.protocol !== "file:" ) {
+                       try {
+                               return new window.XMLHttpRequest();
+                       } catch(e) {}
+               }
+
+               try {
+                       return new window.ActiveXObject("Microsoft.XMLHTTP");
+               } catch(e) {}
+       };
+}
+
 // Does this browser support XHR requests?
 jQuery.support.ajax = !!jQuery.ajaxSettings.xhr();