Sometimes you need to make JSONp calls without including a full third party library.
For example, creating an embed script for websites that you don't have control over which libraries are being used (this may be jQuery, Mootools or something else!)
Include the json.js file (or copy the code and incorporate it into your application)
You can make calls like so:
// Flickr example
JSONp.get({
url : 'http://api.flickr.com/services/feeds/photos_public.gne', // URL of the service
callbackName : 'jsoncallback', // Optional - use if the callback name isn't "callback"
opts : { tags: "cat", tagmode: "any", format: "json" }, // Processed into a query string and appended to the service URL
success : function( json ){
// Do something with the returned JSON
}
});
This is a very basic piece of code intended to be used without a third party library. You can use the code as it is, or take it as a template for something a bit more spectacular!
David Grayston
- http://www.davidgrayston.co.uk
- http://twitter.com/davidgrayston
- https://github.com/davidgrayston
Use as you will