Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to fetch data from server using AngularJS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.69k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: