Erex Erex - 1 year ago 78
AngularJS Question

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

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:

var obj = $.getJSON( ""+ $scope.searchString, function() {
$scope.items = obj.responseJSON.entries;

Is there a method equal to $.getJSON in angularJS? So that I don't have to import the JQuery library.

Thanks in advance, newbie.

This is my solution so far:

function InstantSearchController($scope, $http){
$ = function() {
$http.jsonp(""+ $scope.searchString + "?json_callback=JSON_CALLBACK").success(
function(data, status) {

but I'm getting the error msg:

Uncaught SyntaxError: Unexpected token :

why is this? what am I doing wrong?

Answer Source

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 = [];  
     $ = function() {        
            $http({method: 'JSONP', url: ""+ $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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download