Search code examples
javascriptajaxsame-origin-policy

I'm getting "Cross-Origin Request Blocked" with the same domain


Well my JavaScript calls the url that is the part of the website, so I have no idea why this is "cross-origin".

My AJAX call:

$.ajax({
    url: SITE_URL+'ajax_check.php?p='+P_ID,
    //let's say SITE_URL is http://example.com/dev
    success:function(result){
        alert(result);
    }
});

And this is the error I get in firebug:

"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com/dev/ajax_check.php?p=23. This can be fixed by moving the resource to the same domain or enabling CORS."


Solution

  • As mentioned by VoteyDisciple the url format must be exactly the same. In my situation the page url had a www prefix, but the ajax call url did not. So that's "cross-origin".