Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery ajax request - IE11 Access is denied

The question

I'm making an ajax request via jQuery using the following function:

function ajaxRequest(requestName,responseFunction,parameters) {
 console.log('Making request ' + requestName);
 var now = new Date();
 $.ajax({
    type: "GET",
    url: "ajax.php",
    error: function(jqXHR,textStatus,errorThrown ) {
        console.log('Error: ' + textStatus + ' ' + errorThrown);
    },
    success:function(msg) {
        console.log('Success! ' + msg);
    }
 });
}

What possible reasons for an 'Access is denied' error are there here? Is there anything I can do to get a more meaningful error message?

More information...

I'm currently calling this function to save a value in an input field. This works in all tested browsers.

I also call this function from an onpaste event (i.e. ), to do the same job, and this is what is failing, but only in IE11. The error is just "Access is denied.".

Note that this is not a cross domain request, it is requesting a file in the same directory.

Tested in:

  • Mac + Safari
  • Mac + Chrome
  • WinXP + IE8
  • Win7 + IE9
  • Win 8 + IE10
  • in 8.1 + IE11 (the only one that causes the problem.)

Note that I've stripped out some irrelevant parts of the code, such as using the responseFunction and parameters variable.

like image 501
Ben Avatar asked Nov 13 '14 14:11

Ben


1 Answers

After a lot of research, the only solution I could come up with that works, was to use a setTimeout to cause the AJAX request to trigger after 1 millisecond, instead of instantly. I presume this is some bug in IE11, but hopefully this solution will be useful to someone.

In the end, I changed this code:

ajaxRequest('save_function','response_function',params);

to this:

setTimeout( (function(params) {
    return function() {
        ajaxRequest('save_function','update_save_marksheet_mark',params);
    };
})(params),1);

Just to be clear, the first line of code worked in every browser tested, as far down as IE7, except for IE11.

like image 195
Ben Avatar answered Oct 06 '22 20:10

Ben