Bahamut
Bahamut

Reputation: 1939

Cross domain error while loading document

I'm using 1.8.2 jQuery's ajax to load an rss feed which is an xml document from another server and I have no control over the said server.

$.ajax({
    type: 'GET',
    url: 'http://example.com/feed',
    contentType: "application/xml",
    dataType: 'xml',
    success: function(data){
        alert(data);
    }
});

I keep getting cross-domain errors after the function is called. What am I missing?

Upvotes: 0

Views: 76

Answers (1)

Ivan Zuzak
Ivan Zuzak

Reputation: 18762

You aren't missing anything. You can't access cross-domain data because of the Same-origin policy: http://en.wikipedia.org/wiki/Same_origin_policy

Your options are:

a) use a proxy server on the same domain as your website to make the request for you. Or use something like this: http://www.corsproxy.com/

b) make the server serving the feed you want to fetch include CORS headers, which will enable you to fetch data from it: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Upvotes: 1

Related Questions