To fetch the data from remote server we have to make the ajax request to the server which will return the data in our desired format, and to do that in AngularJS we can use $http service which helps us to communicate with remote server.
To implement $http service we have a following block of code :
<html ng-app="MyApp" >
<head>
<title>AngularJS Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.js"></script>
</head>
<body ng-controller="MyController">
<title></title>
<script src="js/angular.js"></script>
<script>
var app = angular.module('MyApp', []);
app.controller('MyController', function ($http) {
$http({
method: 'Post',
url: 'Default/AddActivity?id=20',
data: { item: 10, name: 'Gaurav' },
headers:{accessToken:'12345'},
dataType: 'json',
}).success(function () {
alert(' success full');
}).error(function(data, status, headers, config) {
alert('error');
})
});
</script>
</body>
0 Comment(s)