Script and JSONP requests are not subject to the same origin policy restrictions. Most APIs that return JSONP data will generate a dynamic callback function name and they typically have a parameter like jsoncallback=?.
However some API's like flickr, Facebook require that you use the callback function name that they specify.
Here are a couple of ways that you can tackle that scenario -
window.fixed_callback = function(data){
alert(data.title);
};
$(function() {
$.getScript("http://api.flickr.com/services/feeds/photos_public.gne?tags=cats&tagmode=any&format=json&jsoncallback=fixed_callback", function(data) {
alert('done'); } );
});
click to enlarge code snippet |
0 comments:
Post a Comment