Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

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: 67334
170
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: 67334
170
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.
 
The knights of nee want a shrubbery. And a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!