Is there a method in angularJS thats equal to getJSON. [Newbie alert]

后端 未结 6 1290
灰色年华
灰色年华 2021-01-12 15:00

I\'m newbie at javascript, angularJS and JQuery, but I have just started programming a angularJS app where i use JQuery to get a JSON from a webserver like this:

<         


        
6条回答
  •  太阳男子
    2021-01-12 15:16

    Because of the help i got from people answering my question I finally managed to fix it, and i did it like this:

    app.controller('myController', function($scope, $http){
        $scope.items = [];  
         $scope.search = function() {        
                $http({method: 'JSONP', url: "http://something.com/lol?callback=JSON_CALLBACK&query="+ $scope.searchString}).
                  success(function(data, status) {
                    $scope.items = data.entries;
                  }).
                  error(function(data, status) {
                    console.log(data || "Request failed");
                });     
         };
    

    Hope this helps anyone who has the same problem in the future :D

提交回复
热议问题