- CSS - Cascaded Style Sheets



|
|
Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
If you want to do cross-domain scripting with XMLHttpRequest, e.g. fetching data from
a remote location but you're on a local page or local XUL application (file:///), you need to tell Mozilla/Firefox about that,
otherwise you get the infamous error:
Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
For further AJAX stuff see:
AJAX/Javascript Form POST Request
AJAX/Javascript XML Tips & Tricks
AJAX/Javascript XML Processing Example/Tutorial
Below is an example that can be run locally (save it to your harddisk and open the page
with Mozilla/Firefox). It will fetch some RSS XML data from wunderground.com and alert it.
Always remember: XMLHttpRequest needs UniversalBrowserRead!
If the page with the XMLHttpRequest is on a http:// URI (on a webserver), it is not possible to
fetch data from another domain!!! This is a security measure of Mozilla/Firefox.
Still, it comes in handy, if you can read remote data from a local application. E.g. you've got
a local XUL application that needs to get data from other servers - Dude! Sweet! :-)
If you're doing some extension to the Mozilla/Firefox browser, you don't need to care about permissions.
Such an extension is installed into the core of the browser anyway, hence it has all privileges.
See: Firefox Statusbar Tutorial or
Firefox Toolbar Tutorial
cross-domain-xmlhttprequest.html
<script type="text/javascript" language="javascript">
// Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
var http_request = false;
function makeRequest(url, parameters) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission UniversalBrowserRead denied.");
}
http_request = false;
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var string = http_request.responseText;
alert(string);
} else {
alert('There was a problem with the request.');
}
}
}
function updateweather() {
makeRequest('http://www.wunderground.com/auto/rss_full/global/stations/16239.xml', '');
}
</script>
<input type="button" name="button" value="GET XML"
onclick="javascript:updateweather();">
Last-Modified: Sat, 04 Feb 2006 16:03:22 GMT
|
|