javascript - AngularJS jsonp success error - Stack Overflow

Hi I'm trying tu get BING MAPS API using Angularjs but I'm getting this error in console:Type

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
Add a ment  | 

3 Answers 3

Reset to default 5

Angular 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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745644764a4637902.html

相关推荐

  • javascript - AngularJS jsonp success error - Stack Overflow

    Hi I'm trying tu get BING MAPS API using Angularjs but I'm getting this error in console:Type

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信