JSONP返回"未捕获的SyntaxError:意外的标记:" AngularJS - routingnumbers.info标记、意外、SyntaxError、JSONP

2023-09-13 02:54:18 作者:久了就旧了

我研究过这个问题,一个可笑的金额,会希望有人能帮助诊断什么是错的。

I've researched this question a ridiculous amount and would hope that someone can help diagnose what is wrong.

我已经试过看着下面SO问题:(SO不会让我张贴由于名声超过2个链接,所以我只是包括路径)

I've already tried looked at the following SO questions: (SO wouldn't let me post more than 2 links due to reputation, so i've just included the paths)

问题/ 16344933 / angularjs-JSONP - 不工作/ 16352746#16352746 问题/ 19269153 / JSONP请求 - 在angularjs-犯规工作样在jQuery的问题/ 19669044 / angularjs-越来越语法错误,在返回的JSON的 - 从-HTTP-JSONP

在许多人......

Among many others......

的东西我曾尝试:我已经添加了&安培;回调= JSON_CALLBACK 的URL的末尾。我已经改变了配置设置,如的responseType:JSON。我也多次重新安排了http.jsonp要求,以确保它是不是编程/文本( HTTP({})及http.jsonp )

Things I have tried: I've added &callback=JSON_CALLBACK to the end of the url. I've changed config settings such as responseType: 'JSON'. I've also rearranged the http.jsonp request multiple times to make sure it was not something programmatic/textual (http({}) & http.jsonp)

这里是我想要做的:抓住从信息 routingnumbers.info/api / 的使用角JSONP请求(服务器不允许CORS)。我能够发出请求成功使用jQuery,但我无法与角度,使其成功。

Here is what i'm trying to do: Grab information from routingnumbers.info/api/ using an angular jsonp request (server does not allow CORS). I am able to make the request successfully with jQuery, but i'm unable to make it successfully with angular.

下面是相应的测试小提琴: http://jsfiddle.net/dqcpa/14/

正如你所看到的,我收到两个错误:

PTED为脚本,但MIME类型文本传输资源间$ P $ /平淡的道:https://routingnumbers.herokuapp.com/api/data.json?rn=071000013&callback=angular.callbacks._0\". angular.min.js:97 未捕获的SyntaxError:意外的标记: Resource interpreted as Script but transferred with MIME type text/plain: "https://routingnumbers.herokuapp.com/api/data.json?rn=071000013&callback=angular.callbacks._0". angular.min.js:97 Uncaught SyntaxError: Unexpected token :

但是,如果您检查铬devtools回应 - 网络,这是正确的:虽然我不知道JSONP将返回jsonpfunction内的响应({MyJson:数据})这是它可以取出挂了。

But if you check the response in chrome devtools - NETWORK, it is correct: Though I do know that jsonp will return the response inside of jsonpfunction({ "MyJson": "Data"}) which is where it is getting hung up at.

下面是原来的code:

Here is the original code:

//$scope.number = '071000013';
var routingApiUrl = 'https://routingnumbers.herokuapp.com/api/data.json?rn=' + $scope.number;
$http({
    method: 'jsonp',
    url: routingApiUrl + '&callback=JSON_CALLBACK',
    responseType: "json"
}).
success(function(data){
    console.log('Success: ' + data);
}).
error(function(data){
    console.log('Error: ' + data);
});

有没有人使用具有角这个API?我猜想有可能是我能够做到的(没有jQuery的)来修改标题,但我一直没能找到任何信息。我也在想,这可能是一个问题的服务器(虽然,如果它在jQuery的正常工作,那会不会是这个问题)。也许这可能是一些与HTTPS

Has anyone used this API with angular? I'm assuming that there may be something I can do (sans jquery) to modify headers, but I have not been able to find any information. I'm also thinking that it could be a server issue (although, if it is working correctly in jquery, that wouldn't be the issue). Maybe this could be something with HTTPS

TL:DR - 角JSONP请求不工作,但具有相同的URL,jQuery的JSONP请求工作。它引用了上面code,我错过什么?

TL:DR - Angular JSONP request is not working, but with the same URL, the jQuery JSONP request is working. Referencing the above code, what am I missing?

任何帮助将是真棒!

编辑:的部分标点符号和东西

Some punctuation and stuff.

推荐答案

acoording这个问题:How摆脱未捕获的SyntaxError的:意外的令牌:尝试加入 angular.callbacks._0(JSON)在你的服务器端的JSON调用。它为我工作

acoording to this question: How to get rid of Uncaught SyntaxError: Unexpected token : try adding angular.callbacks._0 (JSON) around your server side json call. it worked for me

这是plunker http://plnkr.co/edit/oX2UQRBA41FIHpwAP6AA

This was the plunker http://plnkr.co/edit/oX2UQRBA41FIHpwAP6AA