简体   繁体   中英

Why does the Flickr API not let me name my own callback function for a JSONP request? Am I viewing this right?

It appears that when I use my own callback function via JSONP, Flickr wraps the JSON with its own function name called jsonFlickrFeed . And if I type the url/src directly on the browser, I do see that it's indeed wrapped.

Does this mean I'm supposed to name my function to jsonFlickrFeed ? I thought when using JSONP, we get to name our own functions?

PS I've browsed the site for answers, but I couldn't find any direct answer. The only answer I found was that someone did use jsonFlickrFeed as the callback function name ; however, being forced to use the name is what I want clarification on.

I'm also using javascript without jquery.

If you read the Flickr documentation under the callback section it says if you want to specify the callback you need to set jsoncallback to the value you want. They do not follow the pattern of "callback" like most sites use.

Callback Function

If you just want the raw JSON, with no function wrapper, add the parameter nojsoncallback with a value of 1 to your request.

To define your own callback function name, add the parameter jsoncallback with your desired name as the value.

 nojsoncallback=1 -> {...} jsoncallback=wooYay -> wooYay({...}); 

http://api.flickr.com/services/feeds/photos_public.gne?tags=cat+pic+%22&tagmode=any&format=json&jsoncallback=xxx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM