Skip to content
Permalink
Browse files

Make sure we have a fallback when XMLHttpRequest is manually disabled…

…. Fixes #6298.
  • Loading branch information
jeresig committed Sep 28, 2010
1 parent 0368606 commit 873c28425fb64fdb48cfa09d17041bded39b301f
Showing with 24 additions and 12 deletions.
  1. +24 −12 src/ajax.js
@@ -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) {}

This comment has been minimized.

Copy link
@rwaldron

rwaldron Oct 9, 2010

Member

See my comment below - this is the line in question

};
}

// Does this browser support XHR requests?
jQuery.support.ajax = !!jQuery.ajaxSettings.xhr();

7 comments on commit 873c284

@rwaldron

This comment has been minimized.

Copy link
Member

rwaldron replied Oct 9, 2010

This commit causes the error:

Problem at line 5890 character 17: 'e' is already defined.

During the JSLint check

@dmethvin

This comment has been minimized.

Copy link
Member

dmethvin replied Oct 9, 2010

I saw that too. Isn't JSLint wrong on this? The catch creates its own scope for the error arg according to ECMA-262 section 10.2.

@frozzare

This comment has been minimized.

Copy link

frozzare replied Oct 9, 2010

I think that @dmethvin is right. Even if the 'e' exists so will catch replace it to a exception.

@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Oct 9, 2010

The catch creates its own scope for the error arg according to ECMA-262 section 10.2

An ES spec reference? That's borderline c.l.j. talk. Who cares about learning JavaScript give me my jQuery :P </sarcasm>

@ryantenney

This comment has been minimized.

Copy link
Contributor

ryantenney replied Oct 9, 2010

I usually trust Crockford over the ES spec. But I have to ask... does it make any difference whatsoever in this case?

@dmethvin

This comment has been minimized.

Copy link
Member

dmethvin replied Oct 10, 2010

@ryantenney, if two men say they're Jesus, one of them must be wrong. :) Since it's hard to know which is the false idol, John appeased Crockford here: http://github.com/jquery/jquery/commit/da597bcf9014b1827e50c0e8f3b9268318574572

@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Oct 10, 2010

@dmethvin lolwut!?

Please sign in to comment.
You can’t perform that action at this time.