• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

xmlHTTPRequest Access is denied

I get the error "Access is Denied" when I try to call the first line in the following lines of code:


There is actually a URL in the second parameter, and if I paste the URL directly into a browser, it shows me the XML.   However, it doesn't work when I call it between the script tags.   I get the access denied error.   How do I get around this?
1 Solution
>> I get the access denied error.
That's because the browser does NOT allow you to request data from an "External" domain. In other words, if the page where you have that code is currently at:

Then you can request files that reside ONLY in http://www.yoursite.com. IF you tried to get a file from http://www.yahoo.com, you will get that error.

>>How do I get around this?
You begin by accepting the fact that for security reasons, the browser disallow this.  Your alternative is to create a server side script that will get the "external" file for you.

To clarify, create a file on your server (let's call it fetcher.php). Then in your ajax script you call fetcher.php (because it is in your domain). When fetcher.php, is called, IT will fetch the remote url for you and passes the result to your ajax script:

echo file_get_contents('http://www.yahoo.com');
saturationAuthor Commented:
Exactly what I was looking for.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now