Since I couldn’t find a jquery/jsonp example that I liked, here is my stab at it.
Imagine a server with this bit of perl CGI code:
When run, the output looks like this:
This script is called “ws.pl”. It is smart enough to call use a different function name if one is requested by the client.
On the client/JS side, you can use this data this way:
Here, an alert box will appear. Notice that the callback function producing the alert has received the decoded JSON object and is able to use it directly. No need to worry about injecting SCRIPT tags, etc.