Pitzik4
Pitzik4

Reputation: 21

Origin null is not allowed by Access-Control-Allow-Origin (Synchronous, no jQuery)

The first thing I would like to say is that I looked around for an answer to this for quite some time, but everything I found was about jQuery. This is not about jQuery.

I have some code (below), but when I ran it in Firefox then Firebug gave me this big, incomprehensible exception. I tried it in Google Chrome and got something a bit more useful: "XMLHttpRequest cannot load http://www.wikipedia.org/. Origin null is not allowed by Access-Control-Allow-Origin." (If you'd like to know why I was trying to access Wikipedia, I often use it as a test site.) Here is my code:

function requestSite(url) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", url, false);
    xmlhttp.send();
    return xmlhttp;
}

All I tried to do with it was access Wikipedia. Then Google, which gave me the same result. Perhaps it is worth noting that when I triggered the function with a button on the page, it gave me this, while using the console was exactly the same, but without the error message. Another thing that may or may not be worth mentioning is that I was running this file from my local filesystem.

Upvotes: 0

Views: 846

Answers (2)

Hogan
Hogan

Reputation: 70523

This error message means

"You are running this request from your local system".

Making ajax requests to some other domain besides the one you are running the code is (of course) not allowed.

Upvotes: 2

maxedison
maxedison

Reputation: 17553

You can't make an AJAX request to a URL that is on a different domain. It's a basic browser security issue.

Upvotes: 2

Related Questions