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

Getting the progress of a request using AngularJS

The $http() method returns a promise, which is your way of determining what's happening with the request. It defines methods to which you can pass JavaScript functions that operate as event handlers when the underlying network transaction changes state.

How to do it...

The returned promise defines success and error methods, which take event handlers. To use them, we write the following code:

var app = angular.module("aprsapp", []); app.controller("AprsController", ["$scope", "$http", 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 ...

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