The jQuery documentation contains the following example of using $ .getJSON to request a JSONP:
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
function(data) {
$.each(data.items, function(i,item) {
$("<img/>").attr("src", item.media.m).appendTo("#images");
if (i == 3) return false;
});
});
Instead of using this method, which generates a dynamic callback function name because of this parameter:
jsoncallback=?
I want to be able to pre-set this name for hard coding, for example:
jsoncallback=test
This works in the sense that I am running a script, and the JSONP that I have has a JSON object wrapped in a test () call.
However, I cannot figure out how to configure the callback function. Isn't it that simple?
function test(data) {
console.log(data);
}
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=test");
When I try to do this, I return a JSONP that is wrapped in test (), but the test () function that I defined is never called. Did I miss something?
!