如何修复我的jsonp回调以解决“意外令牌”错误,使用angularjs $ http?

时间:2022-06-03 23:08:23

The specs for receiving jsonp from google apps script are not causing an "unexpected token" in the return data.

从谷歌应用程序脚本接收jsonp的规范不会在返回数据中导致“意外令牌”。

I'm using angularjs $http.jsonp - it doesn't like the syntax ?prefix=? at the end of my url to the google apps script.

我正在使用angularjs $ http.jsonp - 它不喜欢语法?prefix =?在我的URL谷歌应用程序脚本的最后。

This works fine with jQuery, but I'm trying to go all angular with this app. Here is a fiddle I forked from a previous user. Here is the request, which is fine:

这适用于jQuery,但我试图通过这个应用程序的所有角度。这是我从前一个用户分叉的小提琴。这是请求,这很好:

function jsonp_example($scope, $http) {
$scope.doRequest = function() {
    var url = "https://script.google.com/macros/s/AKfycbyTnhcsnyXKJqZdF8yAppVQjXX935J9-YTJOHyf7jkea16gSsOA/dev?prefix=?";

    $http.jsonp(url);
};

Have console open, please.

请打开控制台。

1 个解决方案

#1


5  

Try this:

function jsonp_example($scope, $http) {
    $scope.doRequest = function() {
        var url = "https://script.google.com/macros/s/AKfycbyTnhcsnyXKJqZdF8yAppVQjXX935J9-YTJOHyf7jkea16gSsOA/dev?prefix=JSON_CALLBACK";

        $http.jsonp(url).success(function(data) { alert(data) })
    };
}

Works for me: http://jsfiddle.net/sc0ttyd/7MUty/3/

适合我:http://jsfiddle.net/sc0ttyd/7MUty/3/

#1


5  

Try this:

function jsonp_example($scope, $http) {
    $scope.doRequest = function() {
        var url = "https://script.google.com/macros/s/AKfycbyTnhcsnyXKJqZdF8yAppVQjXX935J9-YTJOHyf7jkea16gSsOA/dev?prefix=JSON_CALLBACK";

        $http.jsonp(url).success(function(data) { alert(data) })
    };
}

Works for me: http://jsfiddle.net/sc0ttyd/7MUty/3/

适合我:http://jsfiddle.net/sc0ttyd/7MUty/3/