我如何通过带有角的ajax获取json数据?我尝试了很多,但是我的代码无法正常工作。我的代码:
<!DOCTYPE html> <html lang="en" ng-app="test"> <head> <meta charset="UTF-8"> <title></title> <script src="https://code.angularjs.org/1.6.1/angular.min.js"></script> <script> angular.module('test', []) .controller('TestCtrl', function($scope, $http) { $scope.data = []; $http.get("http://jsonplaceholder.typicode.com/users").then(function(res) { $scope.data = JSON.parse(res); }); }); </script> </head> <body ng-controller="TestCtrl"> <div ng-repeat="item in data"> {{item.id}} </div> </body> </html>
你这样尝试过吗?
<script> var app = angular.module('test', []) app.controller('TestCtrl', function ($scope, $http) { $http.get("http://jsonplaceholder.typicode.com/users").then(function(res,status,xhr) { $scope.data = res.data; }); }); </script>