利用$http获取在服务器的json数据
以下是存储在web服务器上的 JSON 文件:
http://www.runoob.com/try/angularjs/data/Customers_JSON.php
{
"records":[
{"name":'yan1',"age":'11',"sex":'man'},
{"name":'yan2',"age":'12',"sex":'man'},
{"name":'yan3',"age":'13',"sex":'man'},
{"name":'yan4',"age":'14',"sex":'man'},
]
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < div ng-app="myApp" ng-controller="customersCtrl"> < ul > < li ng-repeat="x in names"> {{ x.Name + ', ' + x.Country }} </ li > </ ul > </ div > < script > var app = angular.module('myApp', []); app.controller('customersCtrl', function($scope, $http) { $http.get("http://www.runoob.com/try/angularjs/data/Customers_JSON.php") .success(function(response) {$scope.names = response.records;}); }); </ script > |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步