views:

750

answers:

4

Is there a way to use XMLHttpRequest in combination with other domains?

I would like to parse some xml from Google without having to use a server so it is minimalistically complex to run.

var req = getXmlHttpRequestObject();
...
req.open('GET', 'http://www.google.de/ig/api?weather=Braunschweig', true);
        req.setRequestHeader("Content-Type","text/xml");
        req.onreadystatechange = setMessage;
        req.send(null);

Doing it on the server side is no option at least then I wouldn't have to ask

+5  A: 

Nope, not right now. I believe I read that plans/design's are in the works by standards groups for the future, so we can securely do this.

Cross site scripting vulnerabilities would be rampant other wise.

JSONP is a possible solution if the other sites API supports.

Brian Gianforcaro
jsonp is the magic word, +1
Ali A
+2  A: 

It's a security issue, most (all?) browsers won't let you do that. You can use a hidden IFrame to do your fetching, but it's complex enough that i'd just use a server (or switch to a different language, if i don't have to run in a browser)

Javier
Even with a hidden Iframe your still not alowed to ge the contents of something that's from another domain.
Pim Jager
A: 

That's not possible due to the SOP (Same Origin Policy) that browser have these days to restrict XSS attacks.
You will have to use a server side script (PHP or something).

Pim Jager
A: 

You can try to do something on the serverside. So on your application you make the request to the remote site getting the result and returning it to your client. The AJAX call is then only calling your own server and works.

Vincent Ramdhanie
Did you not read my description?
Thomaschaaf