0

I want to parse a XML document hosted on another domain, is this possible or does it violate the cross domain policy. I know you can $.getScript() from other domains, is it the same for XML? My attempts using $.ajax() has failed.

Liam
  • 27,717
  • 28
  • 128
  • 190
  • Of course it violates the cross domain policy. –  Jun 27 '13 at 15:49
  • Have you tried with a regular XmlHttpRequest? https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest – Sean Airey Jun 27 '13 at 15:52
  • Also, if you provide the code that you tried when using `$.ajax()`, perhaps someone can help you to fix it. – Sean Airey Jun 27 '13 at 15:53
  • If you have control over the other domain, you can do it using a few different methods described in that other question (document.domain, JSONP, iframes, etc.). If you don't, then you'll need to build a simple proxy on your server - your browser can request from your web server, which then makes the call to the other domain and sends the result back to the browser. – Joe Enos Jun 27 '13 at 15:53

2 Answers2

0

Best way to overcome cross domain policy is using JSONP.

Siva Charan
  • 17,940
  • 9
  • 60
  • 95
0

The other domain will need to set the Access-Control-Allow-Origin header with url of the domain you are connecting from (e.g. http://example.com), or * to support any domain.

You can do this via a .htaccess file on Apache if you have the mod_headers module installed by adding a line like this:

Header set Access-Control-Allow-Origin "http://example.com"

Alternatively, if you're serving up the XML via php, you could add the header with the php header function.

header('Access-Control-Allow-Origin: http://example.com');
James Holderness
  • 22,721
  • 2
  • 40
  • 52