最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - AngularJS jsonp success error - Stack Overflow

matteradmin3PV0评论

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/

Post a comment

comment list (0)

  1. No comments so far