| Author |
Ajax call to access remote server
|
Chrix Wu
Ranch Hand
Joined: Nov 15, 2009
Posts: 121
|
|
THE SCRIPT TAG HACKSecurity restrictions prevent us from using XMLHttpRequest to access any
domain other than the one serving up the JavaScript file being executed. This
means we can’t access remote servers like this:
request.open("GET", "http://api.search.yahoo.com/", true);
We can’t use XMLHttpRequest to access the Web APIs offered by so many
sites these days. That’s a real shame because most APIs return their data in
XML, which would then be available in responseXML.
The script element has no such security restrictions. It’s possible to access
a JavaScript file from another domain in this way:
<script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script>
But what if we want to access a remotes server that returns XML rather than json?
|
** SCJP 5.0 84% **
** SCWCD 1.5 76% **
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
You have to use a proxy on your own server.
Ajax call to your server, backend fetches the content, your server sends it to the client.
Eric
|
 |
Chrix Wu
Ranch Hand
Joined: Nov 15, 2009
Posts: 121
|
|
Eric Pascarello wrote:You have to use a proxy on your own server.
Ajax call to your server, backend fetches the content, your server sends it to the client.
Eric
1
thanks
|
 |
 |
|
|
subject: Ajax call to access remote server
|
|
|