---
title: "Working with Ajax in AngularJs"  
description: "Hi everyone in this blog I’m explaining about Ajax in AngularJsIntroduction:AngularJs provides $http control which works as a service to read data fro"  
author: "Anonymous User"  
published: 2015-03-24  
updated: 2018-02-22  
canonical: https://www.mindstick.com/blog/10859/working-with-ajax-in-angularjs  
category: "angular js"  
tags: ["ajax", "angularjs directive", "angularjs controller"]  
reading_time: 2 minutes  

---

# Working with Ajax in AngularJs

Hi everyone in this blog I’m explaining about Ajax in [AngularJs](https://www.mindstick.com/articles/13081/advantages-disadvantages-of-angularjs-is-that-ideal-for-your-project)

##### Introduction:

##

AngularJs provides $http control which works as a service to read [data from the server](https://www.mindstick.com/forum/156656/fetch-the-json-data-from-the-server-through-jquery). The server can make a [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) call to get the records. AngularJs needs data in [JSON format](https://www.mindstick.com/forum/158266/what-is-the-json-format). Once data is ready, $http can be used to get the data from the server in the following manager.

```
function studentController($scope, $http) {        var url = "data.txt";        $http.get(url).success(function (response) {            $scope.students = response;        });    }
```

Here data.txt contains the [student](https://www.mindstick.com/articles/157138/student-loan-default-wage-garnishment-and-student-loan) records. $[http service](https://www.mindstick.com/forum/160660/how-to-use-the-http-service-in-my-angularjs) makes an Ajax call and set [response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt) to its [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) student. “[Students](https://www.mindstick.com/articles/13083/benefits-of-students-who-can-get-online-assignment)” model can be used to be used to draw tables in the html.

##### Example:

##

```
Data.txt:[{"Name" : "Kamlakar Singh","RollNo" : 1027,"Percentage" : "73%"},{"Name" : "Pawan Shukla","RollNo" : 1024,"Percentage" : "70%"},{"Name" : "Rohit","RollNo" : 1006,"Percentage" : "75%"},{"Name" : "Haider","RollNo" : 1002,"Percentage" : "75%"}]
```

##### Angularjs.html

```
<html><head><title>Angular JS Includes</title><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script><style>table, th , td {  border: 1px solid grey;  border-collapse: collapse;  padding: 5px;}table tr:nth-child(odd) {  background-color: #f2f2f2;}table tr:nth-child(even) {  background-color: #ffffff;}</style></head><body><h2>AngularJS Sample Application</h2><div ng-app="mainApp" ng-controller="studentController"><table>   <tr>      <th>Name</th>      <th>Roll No</th>      <th>Percentage</th>   </tr>   <tr ng-repeat="student in students">      <td>{{ student.Name }}</td>      <td>{{ student.RollNo }}</td>      <td>{{ student.Percentage }}</td>   </tr></table></div><script>    var mainApp = angular.module("mainApp", []);     mainApp.controller('studentController', function ($scope) {        var url = "data.txt";        console.log(url);        $http.get(url).success(function (response) {            console.log("Yes");            $scope.students = response;        });        console.log("No");    });</script></body></html>
```

##### Output:

##

To run this example, you need to deploy textAngularJS.htm, data.txt to a webserver. Open textAngularJS.htm using URL of your server in a [web browser](https://www.mindstick.com/blog/301688/best-web-browsers-for-2023). See the result.

![Working with Ajax in AngularJs](https://www.mindstick.com/blogs/2d8bc762-0ab1-45f1-b609-ae1892004ae1/images/1380fea8-7074-4874-967b-9231883ac838.png)

---

Original Source: https://www.mindstick.com/blog/10859/working-with-ajax-in-angularjs

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
