Skip to content
Permalink
Browse files

Make sure that the ActiveX exception is caught if it's unable to be l…

…oaded. Fixes #2849.
  • Loading branch information
jeresig committed Jan 5, 2010
1 parent b2289f3 commit 3f648c4e3abe236b8ec6a19822313be794e5a9df
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/ajax.js
@@ -179,9 +179,14 @@ jQuery.extend({
// so we use the ActiveXObject when it is available
// This function can be overriden by calling jQuery.ajaxSetup
xhr: function() {
return window.XMLHttpRequest && window.location.protocol !== "file:" || window.ActiveXObject ?
new window.XMLHttpRequest() :
new window.ActiveXObject("Microsoft.XMLHTTP");
if ( window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ) {
return new window.XMLHttpRequest();

} else {
try {
return new window.ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {}
}
},
accepts: {
xml: "application/xml, text/xml",
@@ -326,6 +331,10 @@ jQuery.extend({
// Create the request object
var xhr = s.xhr();

if ( !xhr ) {
return;
}

// Open the socket
// Passing null username, generates a login popup on Opera (#2865)
if ( s.username ) {

7 comments on commit 3f648c4

@GarrettS

This comment has been minimized.

Copy link

GarrettS replied Jan 6, 2010

What is using file protocol?

Have you considered creating an identifier for native support in containing scope?

var IS_NATIVE_XHR = typeof XMLHttpRequest != "undefined";
@kangax

This comment has been minimized.

Copy link

kangax replied Jan 7, 2010

Or just declare this whole function conditionally, for best performance.

@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Jan 7, 2010

@garrett IE7+ can't access local files from XMLHttpRequest and has to use ActiveXObject

@jeresig

This comment has been minimized.

Copy link
Member Author

jeresig replied Jan 7, 2010

I just split the function in two: c68fbc2

@GarrettS

This comment has been minimized.

Copy link

GarrettS replied Jan 8, 2010

@jdalton;

Yes, I know XMLHttpRequest doesn't support file:..

I am curios as what sort of application is using file protocol. As in "why do you need that?".

I just committed some XHR stuff, to APE.

@GarrettS

This comment has been minimized.

Copy link

GarrettS replied Jan 8, 2010

Sorry, I meant in IE. XMLHttpRequest doesn't support file in IE.

Other implementations may, but that is not something that should be relied upon; it is an implementation-dependent feature. So I am wondering who is relying on that nonstandard behavior for production code and why it is there. I know the history with jQUery and wanting to support file, but not the reason for wanting.

http://www.w3.org/TR/XMLHttpRequest/

Second, it can be used to make requests over both HTTP and HTTPS (some implementations support protocols in addition to HTTP and HTTPS, but that functionality is not covered by this specification)
@SamWM

This comment has been minimized.

Copy link

SamWM replied Jan 8, 2010

There may be cases where jQuery AJAX may be used on file is serverless intranets or for testing without a web server, i.e. accessed via I:\intranet\index.html for example. Probably rarely used by developers, but is there any harm in including it? MooTools will fail with file (http://github.com/mootools/mootools-core/blob/master/Source/Core/Browser.js#L70) as will Prototype (http://github.com/sstephenson/prototype/blob/master/src/ajax/ajax.js).

There is also the possibility that jQuery may be used in HTML Applications (HTA) or Windows gadgets (although I do not know if people use it or how well it works). Sticking to the standards is important, but why not go further (as long as it doesn't break other browsers or involve too much extra code)?

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