利用$http获取在服务器的json数据

Posted 飘然离去

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用$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‘},
]

}

  

<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>

  

以上是关于利用$http获取在服务器的json数据的主要内容,如果未能解决你的问题,请参考以下文章