Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ajax Interview Questions  New!

Ajax Programming

Error: uncaught exception: Permission denied to call method XMLHttpRequest.open


Hi everyone.

I am working on a Firefox extension which will query a website, and
then parse the results. I have just started learning about AJAX, and
although I have seen lots of working examples, I can't understand why
the following example, (taken from
http://developer.mozilla.org/en/docs/AJAX:Getting_Started#Step_3_.E2....),
won't work.

<script type="text/javascript" language="javascript">
    function makeRequest(url) {
        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        }
        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() {
alertContents(http_request); };
        http_request.open('GET', url, true);
        http_request.send(null);
    }

    function alertContents(http_request) {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                alert(http_request.responseText);
            } else {
                alert('There was a problem with the request.');
            }
        }
    }
</script>
<span
    style="cursor: pointer; text-decoration: underline"
    onclick="makeRequest('http://www.google.com')">
        Make a request
</span>

I have put the code into a stand alone file on my Desktop, which is
opened by Firefox.

Firefox gives me the following error:

Error: uncaught exception: Permission denied to call method
XMLHttpRequest.open

Please could someone point out where I might be going wrong?

Many thanks.

Daz.

You can not call an outside domain. You are restricted by the same domain
policy.

Eric

On 12/20/06, Daz <cutenfu@gmail.com> wrote:

Hi eric.

Thank you for your input. Would you know any methods that I might be
able to use in order to inject the script onto the DOM source? What I
would like to create is an application that will get the information
from several pages, and then use that information to carry out
operations for the user in order to save the user time.

All the best.

Daz.

-----------------------------------------------Reply-----------------------------------------------

Hi,

you can access these other pages via your webserver (in PHP or
whatever), just some kind of proxy. This should be the common way.
Additionally it helps you to leave your code clean.

Matthias

-----------------------------------------------Reply-----------------------------------------------

Matthias,

Thanks for you comments. I guess I was getting a little off-topic, as I
am making a Firefox extension, and would like to enable that extension
to use AJAX to retrieve data from other pages on that website (which
isn't mine).

All the best.

Daz.

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

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

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.
 

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.megasolutions.net/16239.xml', '');
  }
</script>

<input type="button" name="button" value="GET XML" 
  onclick="javascript:updateweather();">


 

uncaught exception: Permission denied to call method XMLHttpRequest.open


i'm trying to create a form that I can put on multiple sites that are on multiple servers. I'm using ajax and php to create this form. I got it to work on the site where all the main files reside, but when I put the form on another site, I get the following error:

uncaught exception: Permission denied to call method XMLHttpRequest.open


by reading the error I can see that there is some sort of security issue with running ajax across multiple sites. How do I go about fixing it, or allowing certain sites to run ajax across sites.

thank you

Search

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc