admin管理员组

文章数量:1026381

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/

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/

本文标签: javascriptAngularJS jsonp success errorStack Overflow