Skip to content

Commit

Permalink
Make sure we have a fallback when XMLHttpRequest is manually disabled…
Browse files Browse the repository at this point in the history
…. Fixes #6298.
  • Loading branch information
jeresig committed Sep 28, 2010
1 parent 0368606 commit 873c284
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/ajax.js
Expand Up @@ -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",
Expand Down Expand Up @@ -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();

Expand Down

7 comments on commit 873c284

@rwaldron
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit causes the error:

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

During the JSLint check

@dmethvin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jdalton
Copy link
Member

@jdalton jdalton commented on 873c284 Oct 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dmethvin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmethvin lolwut!?

Please sign in to comment.