xdevel2000
xdevel2000

Reputation: 21444

Get an XML file using Ajax

When I try to get an XML file (RSS feed) from a site I can't get it.

The web browsers Internet Explorer and Firefox tell me that I have no authorization.

Now I'm behind a proxy, but maybe it produces that message. Could it be that from a site (mine) I can't get other resource of another site (domain) for security reasons?

Upvotes: 1

Views: 1191

Answers (2)

curv
curv

Reputation: 3854

If you're trying to access an XML file on another domain using XMLHttpRequest then you can't, on purpose... it's a security issue. However, a workaround is to use a proxy page to grab the XML, see these:

http://developer.yahoo.com/javascript/howto-proxy.html

http://ejohn.org/blog/cross-site-xmlhttprequest/

http://ajaxpatterns.org/Cross-Domain_Proxy

Upvotes: 2

Daniel Vassallo
Daniel Vassallo

Reputation: 344511

The browser is preventing cross-site scripting. You have to use a relative path, otherwise most browsers will simply refuse to make an AJAX call.

As one possible workaround, you could set up a very simple reverse proxy (with mod_proxy if you are using Apache). This would allow you to use relative paths in your AJAX request, while the HTTP server would be acting as a proxy to any "remote" location.

The fundamental configuration directive to set up a reverse proxy in mod_proxy is the ProxyPass. You would typically use it as follows:

ProxyPass   /ajax/stackoverflow/   http://stackoverflow.com/feeds/

In this case, the browser would be requesting /ajax/stackoverflow/tag?tagnames=javascript but the server would serve this by acting as a proxy to http://stackoverflow.com/feeds/tag?tagnames=javascript.

Upvotes: 1

Related Questions