views:

77

answers:

1

I have an $.ajax() request that queries currency exchange rate information from another web server, which is the reason (I believe) for which I am getting an "Access Is Denied" error on the $.ajax() call.

Is there a way to permit this type of activity?

+3  A: 

Yes, you could use JSONP if the remote server can support it (works only with GET requests and it works with the .ajax function as well). Another option is to create a bridge server script on the same domain.

Here's an article that may help you get started.

Here's how it works:

The server must send the data using the following format:

callback({name : "Smith", id : 1})

where callback must be configurable.

So basically jQuery includes a script tag inside the DOM:

<script type="text/javascript" src="http://distantdomain.com/?jsonp_callback=someRandomName"&gt;&lt;/script&gt;

and the someRandomName function will be executed and passed the JSON object.

Darin Dimitrov
Im not so sure I understand how JSONP works in the jQuery ajax method. It speaks of callbacks?
Jimbo
Thanks. Unfortunately the server sends back an xml response, which can't be changed by me, so i'll need to find another way :(
Jimbo
The callback is an anonymous function that you define and which is called once the response of the server is loaded and this callback is passed the JSON object as argument so that you can manipulate it.
Darin Dimitrov
In case you want a cross browser solution you will need to setup a script on your domain that will delegate the call to the distant server and your AJAX script will query the local server.
Darin Dimitrov
Thanks, nice to have a definitive answer :)
Jimbo
+1 good advices, i just learned new things, hey JIMBO since it is a definitive answer you are supposed to mark it as an answer (duh)
Kronass