Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to restricted URI denied code: 1012

How do you get around this Ajax cross site scripting problem on FireFox 3?

like image 598
Jimmy Chandra Avatar asked Sep 09 '08 06:09

Jimmy Chandra


3 Answers

If you're using jQuery it has a callback function to overcome this:

http://docs.jquery.com/Ajax/jQuery.ajax#options

As of jQuery 1.2, you can load JSON data located on another domain if you specify a JSONP callback, which can be done like so: "myurl?callback=?". jQuery automatically replaces the ? with the correct method name to call, calling your specified callback. Or, if you set the dataType to "jsonp" a callback will be automatically added to your Ajax request.

Alternatively you could make your ajax request to a server-side script which does the cross-domain call for you, then passes the data back to your script

like image 63
Glenn Slaven Avatar answered Nov 19 '22 00:11

Glenn Slaven


To update the answer (I guess, mostly for my benefit when I come looking for this answer later on), if are loading XML or something else, you can always ask the user if he will allow us to read from another site with this code:

try {
    if (netscape.security.PrivilegeManager.enablePrivilege)
        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) { 
    alert("Sorry, browser security settings won't let this program run."); 
    return; 
}

(from the RESTful web services book) But, this only works in firefox, when the html file is loaded from local file. So, not that useful.

like image 6
Jose M Vidal Avatar answered Nov 18 '22 23:11

Jose M Vidal


One more solution: if all you need is the headers, you can specify "HEAD" as the method and it won't trigger the security issue. For instance, if you just want to know if the web page exists.

var client = new XMLHttpRequest();
client.open("HEAD", my_url, false);
client.send(null);
if(client.readyState != 4 || client.status != 200) //if we failed
    alert("can't open web page");
like image 1
Eyal Avatar answered Nov 18 '22 23:11

Eyal