Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

javascript - Error: "Access to restricted URI denied"

Access to restricted URI denied" code: "1012 [Break On This Error]

xhttp.send(null);

function getXML(xml_file) {
  
  if (window.XMLHttpRequest) {
    
    var xhttp = new XMLHttpRequest();  // Cretes a instantce of XMLHttpRequest object
  }
  else {
    
    var xhttp = new ActiveXObject("Microsoft.XMLHTTP");  // for IE 5/6
  }
  
  xhttp.open("GET",xml_file,false);  
  xhttp.send(null);  
  
   var xmlDoc = xhttp.responseXML; 
 
   return (xmlDoc);
}

I'm trying to get data from a XML file using JavaScript. Im using Firebug to test and debug on Firefox.

The above error is what I'm getting. It works in other places i used the same before, why is acting weird here?

Can someone help me why it's occuring?

Update:

http://jquery-howto.blogspot.com/2008/12/access-to-restricted-uri-denied-code.html

I found this link explaining the cause of the problem. But I didn't get what the solution given means can someone elaborate?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Another possible cause of this is when you are working with a .html file directly on the file system. For example, if you're accessing it using this url in your browser: C:/Users/Someguy/Desktop/MyProject/index.html

If that then has to make an ajax request, the ajax request will fail because ajax requests to the filesystem are restricted. To fix this, setup a webserver that points localhost to C:/Users/Someguy/Desktop/MyProject and access it from http://localhost/index.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...