Angularjs http JSONP后出现意外标记
我想创建一个输入字段,它使用GooglePlacesAPI检索建议,以便用户更轻松地填写该字段 我正在使用MEAN.js,使用角度控制器检索信息时遇到问题:Angularjs http JSONP后出现意外标记,angularjs,mean-stack,meanjs,Angularjs,Mean Stack,Meanjs,我想创建一个输入字段,它使用GooglePlacesAPI检索建议,以便用户更轻松地填写该字段 我正在使用MEAN.js,使用角度控制器检索信息时遇到问题: // Get places $scope.getPlaces = function(val) { return $http.jsonp('https://maps.googleapis.com/maps/api/place/autocomplete/json?callback=JSON_CALLBACK', { pa
// Get places
$scope.getPlaces = function(val) {
return $http.jsonp('https://maps.googleapis.com/maps/api/place/autocomplete/json?callback=JSON_CALLBACK', {
params: {
input: val,
types: '(regions)',
language: 'en',
key: 'AIzaSyADMplvJfIzKFslb5KfOdZbCKK2SIYVl-E'
}
}).then(function(response){
var places = [];
angular.forEach(response.predictions, function(item){
places.push(item.description);
});
return places;
});
};
视图尝试使用typeahead组件检索自动建议:
<div class="form-group">
<input type="text" id="location" name="location" class="form-control" ng-model="asyncSelected" typeahead="place for place in getPlaces($viewValue)" typeahead-loading="loadingPlaces" placeholder="Location">
</div>
我检查了控制台,请求返回200 OK,但控制台中出现错误:
未捕获的语法错误:意外标记:
http jsonp请求有什么问题?
我怎样才能修好它
谢谢
干杯
Maurizio你能给我们提供json和这个错误所指的行吗?看起来这篇文章的副本并不能解决我的问题。。。我已经在使用JSON_回调参数。此外,我正在使用Google Place API。@rtucker88感谢您提供的信息,但它没有完全重复,因为我已经使用了JSON_回调,我不知道如何解决它。看起来googleapis的V3不支持JSONP,因此您需要在服务器上使用V2 API或使用“代理”