• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to make XmlHttpRequest calls to another server

 
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
I found a beautiful pie. And a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic