O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing the returned JSON using AngularJS

Handling the returned data with AngularJS is easy because it parses the returned JSON for you and passes the resulting object to the event handler you registered with the promise's success method.

How to do it...

Here's the complete client-side code for our AngularJS application. The success promise's callback just updates the models with the fields of the object we get as a result:

var app = angular.module("aprsapp", []); app.controller("AprsController", function($scope, $http) { $scope.json = ""; $scope.message = "Loaded..."; $scope.doAjax = function() { $scope.debug = "Fetching..."; $scope.json= ""; $scope.message = ""; var request = { call: "kf6gpe-7" }; var promise = $http({ url:"/", method: "POST", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required