Bug Tracker

Modify

Ticket #14475 (closed bug: fixed)

Opened 6 months ago

Last modified 3 months ago

Local Ajax requests don't work in IE 11 (ActiveXObject checking in jQuery fails)

Reported by: sergeyi Owned by: dmethvin
Priority: low Milestone: 1.11
Component: ajax Version: 1.10.2
Keywords: Cc:
Blocking: Blocked by:

Description

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. */

function() {

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

comment:1 Changed 6 months ago by dmethvin

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to ajax

See also #14424.

comment:2 Changed 6 months ago by dmethvin

  • Owner set to jaubourg
  • Status changed from open to assigned

comment:3 Changed 5 months ago by dmethvin

  • Owner changed from jaubourg to dmethvin

comment:4 Changed 5 months ago by dmethvin

  • Milestone changed from None to 1.11

comment:5 Changed 5 months ago by dmethvin

  • Status changed from assigned to closed
  • Resolution set to fixed

comment:6 Changed 5 months ago by timmywil

#14589 is a duplicate of this ticket.

comment:7 Changed 3 months ago by aconsolati@…

This still does not seem to be working correctly in jquery-1.11.0.js with IE11. The original error "Access is Denied" is no longer returned, but the $.get function does not retrieve the local file contents.

A call such as the following will return "No Transport" in the .fail() callback:

$.get(" file://c:/Temp/Master.tmpl.htm", function (templateContents) {

/* do something with templateContents; */

}, "html").fail(function (jqXHR, textStatus) {

/* error will contain "No Transport" */ var error = jqXHR.statusText;

});

Whereas using "c:/Temp/Master.tmpl.htm" as the path (without the  file:// protocol) results in $.get not invoking any callbacks and just skipping to the next line of code.

Are there any examples of how to use $.get to successfully retrieve the contents of a local file in IE11?

Many thanks

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.