ajax - Angular $http jsonp: how to parse through data -
i'm starting learn angular , want play around $http call function. want make request external api:
angular.module('pokedexapp') .controller('mainctrl', function ($scope, $http) { var response; $http.jsonp("http://pokeapi.co/api/v1/pokemon/1/").success(function(response) { response = response; }) $scope.pokemon = response; });
i'm wrong how works. want {{ pokemon }}
out response test it.
i'm getting uncaught syntaxerror: unexpected token :
error , can't tell if it's because return data isn't formatted or what.
the error because in angular try parse response in json type. , failed parse, throw error:
uncaught syntaxerror: unexpected token :
seems in angularjs you'd better handler jsonp response self.
$scope.triggerjsonp = function(){ $http.jsonp("http://pokeapi.co/api/v1/pokemon/1/", {params: {'callback':'eqfeed_callback'}}); }; window.eqfeed_callback = function(data){ $scope.response = data; }
relative issue in jquery.ajax jsonp call showing "uncaught syntaxerror: unexpected token : " , answer use own callback handle this.
Comments
Post a Comment