XMLHttpRequest access denied while trying to access files from web server location - IE8

545 views Asked by At

I am working on javascript where i am trying to access a url path using xmlhttprequest . the code works fine with activexobject ( i dont want to use activex object ) . when i try to call it using xmlhttprequest it does not work . it gives an error saying access denied. i am using IE8 version here . I have already tried the below workaround

  • enabling the "access data sources across domain in internet option"

  • adding trusted sites

if(src) //scr = templates/mytemplate
{
 try{
 var xhr= new XMLHttpRequest();   //new ActiveXObject("Microsoft.XMLHTTP"); works fine 
xhr.onreadystatechange=function()
{
 if(xhr.readyState==4)
{
  log.profile(src);
if(xhr.status==200||xhr.status==0)
{
 //do some action
}
}

element.html(xhr.responseText);
log.profile(src);
xhr.open("GET",src,true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send(null);
}}catch(e){
 alert("unable to load templates"+e); // here i am getting error saying acess denaied 
}

1

There are 1 answers

0
Deepak-MSFT On

Here, you got Access denied error. Looks like you are directly trying to run the HTML page in IE browser. You need to host the web page on any web server. for testing purpose, I hosted this sample page on IIS server. Than you can try to access the web page from IE will help to visit the page without this error.

I tried to make a test with this sample code and I tested it with IE 11 (IE-8 document mode).

<!DOCTYPE html>
<html>
<body>

<h2>Using the XMLHttpRequest Object</h2>

<div id="demo">
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</div>

<script>
function loadXMLDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.responseText;
    }
  };
  xhttp.open("GET", "xmlhttp_info.txt", true);
  xhttp.send();
}
</script>

</body>
</html>

Output:

enter image description here

Based on my testing result, code is working fine with the IE-8 document mode so it should also work in IE-8 browser.