Saturday, July 25, 2015

AngularJS $http.get Ajax calls

In the post AngularJS Ajax using $http we saw that we can perform Ajax calls to the server in AngularJS using $http service, and we saw that $http supports Get, Post, Put and Delete operations. In this post we shall see on how to make a $http.get Ajax call in AngularJS

The following example shows how to make a $http.get call to an Asp.Net Web API Controller method.
WebAPI Get Method
    public class PackageController : ApiController
        PkgEntities objDBContext = new PkgEntities();
public dynamic Get()
var lstPackages = (from Packages in objDBContext.Packages
orderby Packages.PackageId
select new { Packages.PackageId, Packages.Name, Packages.Description, Packages.PackageSQL, Packages.Status });
return lstPackages;

AngularJS call to WebAPI Get method
            .then(function (results) {
                try {
                    scope.packageList =;
                catch (err) {
            }, function (results) {
                alert("Error: " + + "; "
                                      + results.status);

The $http.get method calls the server side WebAPI Get() method, collects the response and stores it in the  packageList property of the $scope object.

Search Flipkart Products:

No comments: