views:

268

answers:

3

Hey guys, is there a way to load XML Data Cross-Domain with JQuery (= client side)?

$.get('http://otherdomain.com/data.xml', function(xml) { }

The above doesn't work - do I have to rely on JSONP, or is there a way to load XML?

+1  A: 

You need to use JSONP.

x1a4
Hmm, thought as much, too bad. Maybe there's still hope, I'll leave the question unanswered for a few hours. Thanks.
Dänu
An alternate method is using a hidden xdomain iframe and communicating with it via `postMessage` and `receiveMessage`, but jsonp is much easier.
x1a4
yeah, problem is, there are still loads of webservices which provide data only as xml. I was trying to implement a "generic" method to receive data.
Dänu
+1  A: 

No way to load XML. So yes, using "standard" xmlhttprequests you need JSONpadding.

If the server supports "Cross-Origin Resource Sharing (CORS)" you can easily receive data from a foreign domain. That means, you have to add a custom header into your XmlHttpRequest ('Origin') and the server decides if it does allow the request or not.

jAndy
A: 

try and use an Iframe, fetch the data and use js to parse it.

Nikro