站长资源网络编程
angularJs中$http获取后台数据的实例讲解
简介1.html
| 网站名称 | 网址 |
| {{v.name}
1.html
<div ng-app="module" ng-controller="ctrl">
<table border="1" width="600">
<tr>
<td>网站名称</td>
<td>网址</td>
</tr>
<tr ng-repeat="v in data">
<td>{{v.name}}</td>
<td>{{v.url}}</td>
</tr>
</table>
</div>
<script>
var m = angular.module('module', []);
//注入http服务
m.controller('ctrl', ['$scope', '$http', function ($scope, $http) {
$http({
method:'get', //get请求方式
url:'1.php' //请求地址
}).then(function(response){
//成功时执行
console.log(response);
$scope.data = response.data; //得到请求的数据
},function(response){
//失败时执行
console.log(response);
});
}]);
</script>
1.php <"htmlcode"> |