-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-Ajax.html
More file actions
101 lines (81 loc) · 2.82 KB
/
11-Ajax.html
File metadata and controls
101 lines (81 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>AngularJS - Ajax</title>
<script src="js/lib/angular.min.js"></script>
<!--
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
-->
<link rel="stylesheet" href="css/estilo.css">
<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 ng-app="mainApp">
<div>
<h3>AngularJS - Ajax</h3>
<p>AngularJS provides $http control which works as a service to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $http can be used to get the data from server in the following manner -</p>
<span ng-include="'subpage/1101-ajax.html'"></span>
</div>
<h3>AngularJS Sample Application</h3>
<div 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 app = angular.module('mainApp', []);
app.controller('studentController', ['$scope', 'ajaxRequest', function($scope, forecast) {
forecast.success(function(data) {
$scope.students = data;
});
}]);
app.factory('ajaxRequest', ['$http', function($http) {
return $http.get('txt/dados.txt')
.success(function(data) {
return data;
})
.error(function(err) {
return err;
});
}]);
/*function studentController($scope, $http) {
var url = "txt/dados.txt";
$http.get(url).success(function(response) {
$scope.students = response;
});
}*/
// não funciona com a versão 1.5
</script>
<!--
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
-->
</body>
</html>