Cross Domain (External) Ajax calls with JQuery / Javascript

Thanks, I wasn’t aware of this crossDomain option in JQuery, but I found James Padolseys’ cross-domain Jquery guide helpful. The Use jQuery site also has a good example and demo of cross domain, Flash Proxy and YQL.

Do you need to use this code

Issues

1. As of jQuery 1.5, the success callback function receives a “jqXHR” object (in jQuery 1.4, it received the XMLHttpRequest object). However, since JSONP and cross-domain GET requests do not use XHR, in those cases the jqXHR and textStatus parameters passed to the success callback are undefined.

2. Cross-domain requests are inherently insecure. Either you are sending credentials over clear text, OR, you cannot make cross-domain requests (not without an ugly client side warning atleast) on HTTPS.

Solution

jQuery 1.5, there has been a new property added to $.ajax. It’s called ‘crossDomain’.Default: false for same-domain requests, true for cross-domain requests. If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true.

The server side redirection is quite simple to do in PHP, as shown below,

1: $data = '{"name" : "hello world"}';
2: echo $_GET['jsoncallback'] . '(' …

View original post 216 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s