0
function getInfo()
{

    var URL="https://api-oauth2.mendeley.com/oauth/authorize?client_id=374&redirect_uri=https://localhost/api/mendeley/mendeley.php&response_type=code&scope=all&JSON=1";
    $.ajax({
        url: URL,
        type: 'get',
        dataType: "jsonp",
        jsonpCallback: "https://192.168.2.210/api/mendeley/mendeley.php",
        converters: {
            'text json': true
        },
        success: function (data) {
            console.log(data.content);


        },
        error: function(e) {
            console.log(e);
        }
    });
}

当我调用这个函数时,这给了我错误
SyntaxError: syntax error

4

1 回答 1

0

你有几个问题。


jQuery 文档

jsonpCallback
类型:String 或 Function()
指定 JSONP 请求的回调函数名称。将使用此值代替 jQuery 自动生成的随机名称。最好让 jQuery 生成一个唯一的名称,因为这样可以更轻松地管理请求并提供回调和错误处理。当您想要启用更好的 GET 请求浏览器缓存时,您可能需要指定回调。从 jQuery 1.5 开始,您还可以为此设置使用函数,在这种情况下,jsonpCallback 的值设置为该函数的返回值。

https://192.168.2.210/api/mendeley/mendeley.php不是有效的 JavaScript 函数名称。


如果我访问https://api-oauth2.mendeley.com/oauth/authorize?client_id=374&redirect_uri=https://localhost/api/mendeley/mendeley.php&response_type=code&scope=all&JSON=1or https://api-oauth2.mendeley.com/oauth/authorize?client_id=374&redirect_uri=https://localhost/api/mendeley/mendeley.php&response_type=code&scope=all&JSON=1&callback=something,我会得到一个 HTML 文档,提示我登录。

您需要访问真正的 JSONP 端点才能使用 JSONP。

于 2014-05-22T12:41:55.527 回答