请问javascript或者angularJS如何使用Restful API获取后台接口的数据,语法如何写?
2条回答 默认 最新
- weixin_43687695 2018-12-12 08:59关注
//页面
< script type="application/javascript" src="../js/xxx.js">
< table class="table table-striped">
< thead>
< tr>
< th>用户名
< th>密码
< /tr>
< /thead>
< tbody >
< tr ng-repeat="user in users">
< td>{{ user.username }}
< td>{{ user.loginpass }}
< /tbody>
< /table >//js中:
angular
.module('myApp', [])
.controller(
'userCtrl',
function($scope, $http, $window) {
// 列表绑定
$http({
method : 'GET',
url : '/xxx/xxx',
params : {
'username' : 'xxx'
}
}).then(function successCallback(response) {
$scope.users = response.data;
}, function errorCallback(data) {
alert(data);
});
});本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报