The YQL API support the JSONP format which allow you to specify a Javascript function to handle the data (XML / JSON) return from the API. A normal JSON will return a string which is a javascript object like:
{key1:”value1″,key2:10.35}
While a JSONP will look like:
js_function({key1:”value1″,key2:10.35});
Which the return string from server will be a valid javascript function call and passing a object literal (or the original JSON string) into the function. For more on JSONP, there is an article on Ajaxian.
As you can see above, the handling function will be a global functions in order to make the JSONP to work. Also, the scope of the calling function / object will be completely loss. So I created a simple YQL client which do the auto scope fixing. It works like YUI2′s connection manager and support a callback object which you can specify a method to handle the JSON return, the scope of “this” object, timeout of your YQL call, and pass on argument to the handling function.
Here is a simple demo using the javascript yql client to get the digg’s rss feed.