jQuery的阿贾克斯 - 的tumblr API第2版 [英] Jquery Ajax - Tumblr API v2

查看:116
本文介绍了jQuery的阿贾克斯 - 的tumblr API第2版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想钻研的tumblr的阴暗世界的深处,无法理解,并得到了以下错误:

I'm trying to delve into the depths of the murky world of Tumblr, and can't understand how to get over the following error:

Uncaught SyntaxError: Unexpected token :

我相信这可能是因为我找回了JSON,但尝试使用JSONP。这里就是我想要送:

I believe it may be because I'm getting back json, but trying to use jsonp. Here's what I'm trying to send:

$(function(){
$.ajax({
    type: "GET",
    url : "http://api.tumblr.com/v2/blog/MyTumblrName.tumblr.com/info",
    dataType: "jsonp",
    data: {
        api_key : "MyTumblrApi"
    },
    success: function(data){
        console.log(data);
    },
});
});

我得到一个200 OK响应,并且数据,但仍出现上述错误(我不明白,想知道更多关于)

I get a 200 OK response, and the data but still the above error (which I don't understand and would like to know more about)

的tumblr还亲切地指出以下,但我不清楚具体情况。

Tumblr also kindly points out the following, but I'm unclear on the specifics.

使用HTTP GET进行的所有请求都JSONP功能。要使用JSONP,   追加JSONP =和你的回调函数来请求的名称。   JSONP请求都将返回200 HTTP状态code,但会   反映真实的状态code的JSON响应的元领域。

All requests made with HTTP GET are JSONP-enabled. To use JSONP, append jsonp= and the name of your callback function to the request. JSONP requests will always return an HTTP status code of 200 but will reflect the real status code in the meta field of the JSON response.

任何帮助将是真棒,谢谢!

Any help would be awesome, thanks!

推荐答案

做什么的tumblr告诉你 - 一个回调函数的名字添加到请求

Do what Tumblr is telling you to - add a callback function name to the request

myJsonpCallback = function(data)
{
    console.log(data);
}

$.ajax({
    type: "GET",
    url : "http://api.tumblr.com/v2/blog/MyTumblrName.tumblr.com/info",
    dataType: "jsonp",
    data: {
        api_key : "MyTumblrApi",
        jsonp : "myJsonpCallback"
    }
});

=============================================== =========

========================================================

编辑:的console.log的是一个语法错误,因为我没有实际测试此code。

The console.log thing is a syntax error since I didn't actually test this code.

发生了什么成功?我真的不知道。探路:)它可能会被调用,但数据参数可能为空或东西。 这里的问题是,jQuery的名字是回调参数回调,其中作为的tumblr期待 JSONP 。当200响应jQuery的可能只是的eval() S中的反应,这也就是为什么 myJsonpCallback 实际上是所谓的。

What happens to success? I don't really know. Try and find out :) It will probably be called but data parameter likely be null or something. The issue here is that jQuery names it's callback parameter callback, where as Tumblr is expecting jsonp. Upon 200 response jQuery likely simply eval()s the response, which is why myJsonpCallback is actually called.

这篇关于jQuery的阿贾克斯 - 的tumblr API第2版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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