Loading JSON from another domain with jQuery

Following this example on the JQuery docs only got me so far.

I knew that you needed to pass a URL to getJSON() and append a callback parameter to the end of it:

$.getJSON(“http://www.example.com? jsoncallback=?”);

But then what? JQuery will look at the data returned for a call to ‘jsoncallback’ so to get this to work you’ll need your server side code to return a snippet of JavaScript too.

Wrap the JSON output in a call to ‘jsoncallback’:

jsoncallback ({"name" : "hello world"});

jQuery will replace the questionmark at the end of the URL with this function call which will be executed by the client, so therefore we need to define the jsoncallback function too:

function jsoncallback(data){

// do some stuff with the JSON here!

}