This article mainly introduces how to use AJAX in AngularJS. The example is very simple and cannot fully reflect the powerful functions of AJAX Dynamic Refresh, for more information, see the $ http control provided by AngularJS, which can be used as a service to read data from the server. The server can call a database to obtain records. AngularJS requires data in JSON format. Once data is ready, $ http can obtain data from the server in the following ways.
function studentController($scope,$http) {var url="data.txt"; $http.get(url).success( function(response) { $scope.students = response; });}
Here, the student records included in data.txt. $ Http service enables Ajax to call and set attributes for its students. The "student" model can be used to draw HTML tables.
Example
Data.txt
The Code is as follows:
[
{
"Name": "Mahesh Parashar ",
"Maid": 101,
"Percentage": "80%"
},
{
"Name": "Dinkar Kad ",
"Maid": 201,
"Percentage": "70%"
},
{
"Name": "Robert ",
"Maid": 191,
"Percentage": "75%"
},
{
"Name": "Julian Joe ",
"Maid": 111,
"Percentage": "77%"
}
]
TestAngularJS.html
Angular JS uplodesAngularJS Sample Application
Name |
Roll No |
Percentage |
{Student. Name }} |
{Student. RollNo }} |
{Student. Percentage }} |
Script function studentController ($ scope, $ http) {var url = "data.txt"; $ http. get (url ). success (function (response) {$ scope. students = response;});} script