Local Ajax requests don't work in IE 11 (ActiveXObject checking in jQuery fails)
|Reported by:||sergeyi||Owned by:||dmethvin|
When you open any HTML page locally (through the file:/// protocol) in IE 11 that uses $.ajax to load any local file an exception is ocurred "Access is denied". This happens only in IE 11 and only when you open HTML page locally, it applies to all jQuery versions.
jQuery has the following code to work with XMLHttpRequest in IE: =============================== jQuery.ajaxSettings.xhr = window.ActiveXObject ?
/* 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. */
return !this.isLocal && createStandardXHR() createActiveXHR();
} : For all other browsers, use the standard XMLHttpRequest object createStandardXHR;
Everything is good except one thing: IE11 handles "window.ActiveXObject" in a strange way. It still returns a function, but if you try to get its type "typeof(window.ActiveXObject)" it will return "undefined" (though in IE10 it returns "function"). So the statement "window.ActiveXObject ? true : false" in IE11 will always return false. That's why in IE11 "createStandardXHR" is always used, while createActiveXHR is never used (even locally). This causes a problem that any AJAX request to a file from locally opened HTML web page will fail with the error "Access is denied".
To fix the problem it's enough to change the condition: use "window.ActiveXObject !== undefined ?" instead of "window.ActiveXObject ?"
A couple of words about changes with ActiveXObject in IE 11 can be found here http://msdn.microsoft.com/en-us/library/ff955298(v=vs.85).aspx
Change History (7)
comment:1 Changed 2 years ago by dmethvin
- Component changed from unfiled to ajax
- Priority changed from undecided to low
- Status changed from new to open
comment:2 Changed 2 years ago by dmethvin
- Owner set to jaubourg
- Status changed from open to assigned
comment:5 Changed 2 years ago by dmethvin
- Resolution set to fixed
- Status changed from assigned to closed