admin管理员组文章数量:1434908
Hi I'm trying tu get BING MAPS API using Angularjs but I'm getting this error in console:
TypeError: $http.jsonp(...).success is not a function
Here is my controller
.controller('bingMaps', ['$scope', '$http', MapController]);
function MapController($scope, $http) {
var vm = this;
vm.mapsearch = function() {
var url = ";key=MYKEY&o=json";
$http.jsonp(url)
.success(function(data){
console.log('success');
})
.error(function () {
console.log('error')
});
}
}
Hi I'm trying tu get BING MAPS API using Angularjs but I'm getting this error in console:
TypeError: $http.jsonp(...).success is not a function
Here is my controller
.controller('bingMaps', ['$scope', '$http', MapController]);
function MapController($scope, $http) {
var vm = this;
vm.mapsearch = function() {
var url = "http://dev.virtualearth/REST/v1/Locations?callback=JSON_CALLBACK&key=MYKEY&o=json";
$http.jsonp(url)
.success(function(data){
console.log('success');
})
.error(function () {
console.log('error')
});
}
}
Share
Improve this question
asked Dec 12, 2016 at 10:54
Edin PuzicEdin Puzic
1,0482 gold badges23 silver badges43 bronze badges
3 Answers
Reset to default 5Angular v1.6 removed success
and error
methods from JSONP:
https://github./angular/angular.js/blob/master/CHANGELOG.md
You aren't using jQuery. There is no success
method. The function returns a standard promise. It has a then
method (which takes two arguments, the success callback and the error callback).
See the documentation for examples.
There are a few issues in your Bing Maps REST URL:
- There is no callback parameter. There is a jsonp parameter.
- You haven't provided a query to search for, so there will be an error with the request.
Here is a modified version of your query:
http://dev.virtualearth/REST/v1/Locations?jsonp=JSON_CALLBACK&key=MYKEY&o=json&q=[your search query]
I remend taking a look at the best practices for Bing Maps:
https://msdn.microsoft./en-us/library/dn894107.aspx
There is also a useful blog post on how to use the Bing Maps REST services with different JavaScript frameworks here:
https://blogs.bing./maps/2015/03/05/accessing-the-bing-maps-rest-services-from-various-javascript-frameworks/
本文标签: javascriptAngularJS jsonp success errorStack Overflow
版权声明:本文标题:javascript - AngularJS jsonp success error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745644764a2668067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论