• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax call to access remote server

 
Chrix Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic