Error: "Access to restricted URI denied"

50,355

Solution 1

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

Solution 2

Sounds like you are breaking the same origin policy.

Sub domains, different ports, different protocols are considered different domains.

Solution 3

Try adding Access-Control-Allow-Origin:* header to the server side script that feeds you the XML. If you don't do it in PHP (where you can use header()) and try to read a raw XML file, you probably have to set the header in a .htaccess file by adding Header set Access-Control-Allow-Origin "*". In addition you might need to add Access-Control-Allow-Headers:*.

Also I'd recommend to replace the * in production mode to disallow everybody from reading your data and instead add your own url there.

Solution 4

Without code impossible to say, but you could be running foul of the cross-site ajax limitation: you cannot make ajax requests to other domains.

Share:
50,355
Bala
Author by

Bala

Updated on December 30, 2020

Comments

  • Bala
    Bala over 3 years

    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?

  • StanE
    StanE over 7 years
    >"Also I'd recommend to replace the * in production mode to disable everybody from reading your data and instead add your own url there." Note, that this is purely optional for clients and only browsers respect this. It does not prevent anyone from reading your data.