Accessing tumblr posts with JSON/JSONP

ぐ巨炮叔叔 提交于 2019-12-12 18:06:57

问题


Here is a fiddle I'm working on.

I'm trying to load the posts from ftsstudios.tumblr.com with JSONP, and then using that data on a post reader.

get_data = function (data) {
    FTSPosts.raw = data;
};
$.ajax({
    url: "//api.tumblr.com/v2/blog/ftsstudios.tumblr.com/posts?api_key=myapikey&limit=20&jsonp=get_data",
    dataType: "jsonp"
});

The above snippet should set FTSPosts.raw to the response obtained.

The problem with this is that the data retrieved by get_data returns undefined.

What is the problem?


回答1:


There was a few errors in the code. But the answer to the question is:

get_data = function (data) {
   FTSPosts.raw = data;
};
$.ajax({
   url: "//api.tumblr.com/v2/blog/ftsstudios.tumblr.com/posts?api_key=myapikey&limit=20",
   dataType: "jsonp",
   jsonp: "jsonp"
}).success(get_data);

2 things:

  • If you set the data type to "jsonp" you don't need to provide in the url the callback (jquery does it internally)
  • The parameter for the callback is by default "callback" if you need to change it add as an option jsonp: "the_parameter_callback"


来源:https://stackoverflow.com/questions/16133509/accessing-tumblr-posts-with-json-jsonp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!