IE 11 Error - Access Denied - XMLHttpRequest

I have a strange error with IE11 and ajax. For almost all the requests that I use with the code below, everything is fine, but when I try to use it in combination with the copy + paste method, it returns an access error. So to summarize

  • This code usually works in most browsers for all the functions I wrote.
  • In IE 11 + Windows 8.1, it works in most cases, except when a specific copy and paste function is performed.
  • Interestingly, when using IE 11, but with a different Document mode, such as 8, I still get the same error, although it works initially in IE8 + Windows 7
  • Error: "Access Denied"

Here is the AJAX code:

function ajaxRequest(requestName,responseFunction,parameters) { var xmlhttp; if (requestName.length==0) return; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { if(xmlhttp.responseText == 'Error') alert('Error processing request. Please refresh the page and try again'); else if(xmlhttp.responseText != '') eval(responseFunction+"('"+xmlhttp.responseText+"')"); } } var now = new Date(); var url = "control/ajax.php?request="+requestName+"&parameters="+parameters+"&timestamp"+now; xmlhttp.open("GET",url,true); xmlhttp.send(); } 

In the failure example, the following variables were set:

requestName: "save_marksheet_mark" responseFunction: "update_save_marksheet_mark" parameters: [60962,1284,5]

Is there something wrong with this code? Is there a reason why IE11 throws an error with this code, in particular, circumstances?

+9
source share
2 answers

This question seems to get a lot of views, so just in case someone wondered, I solved this problem using setTimeout () in the original AJAX call. For instance:

 setTimeout(function() { ajaxRequest('save_mark','save_mark_completed',[60962,1284,5]) }, 1); 

I assume this is some kind of bug in IE. This is just 1 millisecond!

+9
source
 setTimeout(function() { ajaxRequest('save_mark','save_mark_completed',[60962,1284,5]) }, 1); 

This worked for me on the first call after loading the page, but later calls again started showing Access denied

0
source

Source: https://habr.com/ru/post/978096/


All Articles