使用JSON/JSONP访问tumblr帖子 [英] Accessing tumblr posts with JSON/JSONP

查看:117
本文介绍了使用JSON/JSONP访问tumblr帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我正在研究的小提琴.

Here is a fiddle I'm working on.

我正在尝试使用JSONP从ftsstudios.tumblr.com加载帖子,然后在帖子阅读器上使用该数据.

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"
});

以上代码段应将FTSPosts.raw设置为获得的响应.

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

此问题是get_data检索到的data返回undefined.

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

出什么问题了?

推荐答案

代码中有一些错误.但是问题的答案是:

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件事:

  • 如果将数据类型设置为"jsonp",则无需在url中提供回调(jquery在内部进行)
  • 如果需要更改,则回调参数默认为"callback"(添加)作为选项jsonp: "the_parameter_callback"

这篇关于使用JSON/JSONP访问tumblr帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆