AngularJS JSONP$http参数“意外令牌”
我在AngularJS中有一个JSONP问题。它在没有必要的参数时工作,但在参数多于强制回调时返回“意外令牌”错误:JSON_回调AngularJS JSONP$http参数“意外令牌”,angularjs,jsonp,Angularjs,Jsonp,我在AngularJS中有一个JSONP问题。它在没有必要的参数时工作,但在参数多于强制回调时返回“意外令牌”错误:JSON_回调 angular.module('myApp.controllers', []) .controller('myCtrl', function($scope, $http) { /* this works */ $http({method: 'JSONP', params:{'callback':'JSON_CALLBACK'},
angular.module('myApp.controllers', [])
.controller('myCtrl', function($scope, $http) {
/* this works */
$http({method: 'JSONP',
params:{'callback':'JSON_CALLBACK'},
url: 'https://graph.facebook.com/paris'}).success(function(data) {
$scope.fbchannel = data
}).error(function(err) {
console.log(err);
});
/* this works not: Uncaught SyntaxError: Unexpected token : */
$http({method: 'JSONP',
params:{'callback':'JSON_CALLBACK', 'address':'Paris', 'sensor':'false'},
url: 'http://maps.googleapis.com/maps/api/geocode/json'}).success(function(data) {
$scope.gmaps = data
}).error(function(err) {
console.log(err);
});
});
我认为错误是因为googleapi返回的是JSON而不是JSONP。您可能想重新检查他们的api以获得JSONP。谢谢,但是我在文档中找不到其他调用。我还尝试了不同的API。当我提供http参数时,总是会收到此错误消息。它不仅与谷歌API有关。