显示“未捕获的SyntaxError:意外令牌:"的JSONP调用; [英] JSONP call showing "Uncaught SyntaxError: Unexpected token : "

查看:93
本文介绍了显示“未捕获的SyntaxError:意外令牌:"的JSONP调用;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

$.ajax({
        url: 'https://api.flightstats.com/flex/schedules/rest/v1/json/flight/AA/100/departing/2013/10/4?appId=19d57e69&appKey=e0ea60854c1205af43fd7b1203005d59&callback=?',
        dataType: 'JSONP',
        jsonpCallback: 'jsonCallback',
        type : 'GET',
        async: false,
        crossDomain: true,
        success: function(data) {
            console.log(data);
        }
    });

我做错了什么?我应该在这里添加或更改任何内容吗? 任何帮助,将不胜感激. 谢谢

What am I doing wrong? should I add or change anything in here? Any help would be appreciated. Thanks

推荐答案

工作小提琴:

http://jsfiddle.net/repjt/

$.ajax({
    url: 'https://api.flightstats.com/flex/schedules/rest/v1/jsonp/flight/AA/100/departing/2013/10/4?appId=19d57e69&appKey=e0ea60854c1205af43fd7b1203005d59',
    dataType: 'JSONP',
    jsonpCallback: 'callback',
    type: 'GET',
    success: function (data) {
        console.log(data);
    }
});

我不得不手动将回调设置为callback,因为这似乎是远程服务所支持的全部.我还更改了URL以指定我想要jsonp.

I had to manually set the callback to callback, since that's all the remote service seems to support. I also changed the url to specify that I wanted jsonp.

这篇关于显示“未捕获的SyntaxError:意外令牌:"的JSONP调用;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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