Menu ▼


AngularJS AJAX $http

The $http service provides access to server calls via browser XMLHttpRequest. In this section we will see how make call to server methods.

syntax:
var app = angular.module("myApp", []);
app.controller("myCntrl", function ($scope, $http) {
    var httpreq = {
        method: 'POST',
        url: 'Default.aspx/GetList',
        headers: {
            'Content-Type': 'application/json; charset=utf-8',
            'dataType': 'json'
        },
        data: {}
    }
    $http(httpreq)
    .success(function (response) { $scope.names = response.d; })
});

method : Defines access type is POST or GET
url : Address of web method
headers: Defines Content-Type & dataType
data : Defines any input parameters
$http(httpreq) : makes the XMLHttpRequest
.success : fires when the execution of web method returned successfully.





comments powered by Disqus


Search dotnetlearners.com