File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to make XmlHttpRequest calls to another server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to make XmlHttpRequest calls to another server" Watch "How to make XmlHttpRequest calls to another server" New topic
Author

How to make XmlHttpRequest calls to another server

Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
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

Joined: Jan 10, 2002
Posts: 61010
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
Could you please elaborate a bit about the process?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

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

Joined: Aug 23, 2006
Posts: 40
Thanks very much for elaborating the process.

I got it working.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make XmlHttpRequest calls to another server