国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

AngularJS Ajax詳解及示例代碼

2019-11-20 09:13:27
字體:
來源:轉載
供稿:網友

AngularJS提供$http控制,可以作為一項服務從服務器讀取數據。服務器可以使一個數據庫調用來獲取記錄。 AngularJS需要JSON格式的數據。一旦數據準備好,$http可以用以下面的方式從服務器得到數據。

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

在這里,data.txt中包含的學生記錄。 $http服務使Ajax調用和設置針對其學生的屬性。 “學生”模型可以用來用來繪制 HTML 表格。

例子

data.txt

[{"Name" : "Mahesh Parashar","RollNo" : 101,"Percentage" : "80%"},{"Name" : "Dinkar Kad","RollNo" : 201,"Percentage" : "70%"},{"Name" : "Robert","RollNo" : 191,"Percentage" : "75%"},{"Name" : "Julian Joe","RollNo" : 111,"Percentage" : "77%"}]

testAngularJS.html

<html><head><title>Angular JS Includes</title><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="" 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>function studentController($scope,$http) {var url="data.txt";  $http.get(url).success( function(response) {              $scope.students = response;            });}</script><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script></body></html>

輸出

要運行這個例子,需要部署textAngularJS.html,data.txt到一個網絡服務器。使用URL在Web瀏覽器中打開textAngularJS.html請求服務器。看到結果如下:

以上就是AngularJS Ajax的基礎資料整理,后續繼續整理相關資料,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高陵县| 宾川县| 天水市| 马公市| 辰溪县| 白山市| 米易县| 新津县| 禄劝| 罗源县| 玛曲县| 苗栗县| 栾城县| 勃利县| 绥芬河市| 漠河县| 兰坪| 陆丰市| 长丰县| 高尔夫| 南澳县| 光山县| 河曲县| 英山县| 边坝县| 上虞市| 乐昌市| 隆回县| 南丹县| 沭阳县| 宜兰市| 玉树县| 富源县| 兴仁县| 双流县| 乡宁县| 上饶市| 丹棱县| 乐业县| 常宁市| 黄陵县|