Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make XmlHttpRequest calls to another server

 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a webpage in which I have DIV.
On click of a button, I want to load that DIV with response from a resource on a different host/server.
When I tried this I got javascript error 'Permission denied'.
It is working for normal requests however it is failing for AJAX requests.
Please share your views on this problem.

Thanks.

Prabhakar
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64835
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Part of the Ajax security sandbox is the inability to make requests to resources on servers other than one that served the page.

One way to get around this is to create a proxy relay on your own server that relays the request to the remote server from the local server. Because the request is made from the server rather than browser, the security sandbox is circumvented.

If you're interested in reading about this at length, I go into great detail on how to do this in the Web Services chapter of Ajax in Practice.
 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please elaborate a bit about the process?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64835
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'm certainly not going to write a chapter's worth of material in a forum.

Basically you make the request to your local server, perhaps to a servlet. The servlet then uses the Java networking API (or a 3rd party library that makes it easier) to make a request to remote server. The servlet then gathers the remote response and relays it to the client.

Libraries such as HttpClient are very helpful.
 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for elaborating the process.

I got it working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic