简体   繁体   English

为什么Flickr API不让我为JSONP请求命名我自己的回调函数? 我在看这个吗?

[英]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 . 看来,当通过JSONP 使用我自己的回调函数时 ,Flickr会用自己的函数名称jsonFlickrFeed包裹JSON。 And if I type the url/src directly on the browser, I do see that it's indeed wrapped. 而且,如果我直接在浏览器中键入url / src, 我确实会看到它确实已包装。

Does this mean I'm supposed to name my function to jsonFlickrFeed ? 这是否意味着我应该将函数命名为jsonFlickrFeed I thought when using JSONP, we get to name our own functions? 我以为使用JSONP时,我们会命名自己的函数吗?

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 ; 我发现的唯一答案是有人确实使用jsonFlickrFeed作为回调函数名称 however, being forced to use the name is what I want clarification on. 但是,我想澄清一下被迫使用该名称。

I'm also using javascript without jquery. 我也在使用没有jquery的javascript。

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. 如果您在回调部分下阅读了Flickr文档 ,它说如果您要指定回调,则需要将jsoncallback设置为所需的值。 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. 如果只需要原始JSON,而没有函数包装,则将参数nojsoncallback的值设置为1到您的请求中。

To define your own callback function name, add the parameter jsoncallback with your desired name as the value. 要定义自己的回调函数名称,请添加参数jsoncallback并使用所需的名称作为值。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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