引用错误:响应未定义 AngularJs



我正在按照本教程从数据库中检索数据。从服务器派生的数据是一个 json 数组,它包含以下两个对象:

[{"_id":{"$oid":"5ae81566f3a9bd1fe8002d34"},"Customer_Name":"cXQzbXlUeHRVckFvVGpoVUQxaHNoQT09","Responsiple_User":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Phone_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","ID_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Sale":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Resposible_Sales":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","City":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Job":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Monhthly_Income":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Number_Of_Months":"SVFxZVJkWG0vaUhxSUxFNzdrWjZCZz09","Monthly_installment_of_the_client":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","First_Payment":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Bank":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Financial_Situation":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Account":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Notes":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Date":"2018-05-01 09:21:10"},{"_id":{"$oid":"5ae8157ff3a9bd1fe8002d36"},"Customer_Name":"aGxveGF1SGxKWXpFajgzSGI0RmE0QT09","Responsiple_User":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Phone_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","ID_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Sale":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Resposible_Sales":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","City":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Job":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Monhthly_Income":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Number_Of_Months":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Monthly_installment_of_the_client":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","First_Payment":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Bank":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Financial_Situation":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Account":"SVFxZVJkWG0vaUhxSUxFNzdrWjZCZz09","Notes":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Date":"2018-05-01 09:21:35"}]

我修改了教程中的代码,以仅显示表中的 json 数据。问题是我一直得到响应问题没有定义。下面是我的代码

<!DOCTYPE html>  
<!-- index.php !-->  
<html>  
<head>  
<title>test</title>  
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>  
</head>  
<body>  
<br /><br />  
<div class="container" style="width:500px;">  
<h3 align="center">AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</h3>  
<div ng-app="myapp" ng-controller="usercontroller" ng-init="displayData()">  
<table class="table table-bordered">  
<tr>  
<th>First Name</th>  
<th>Last Name</th>  
</tr>  
<tr ng-repeat="x in names">  
<td>{{x.City}}</td>  
<td>{{x.last_name}}</td>  
</tr>  
</table>  
</div>  
</div>  
</body>  
</html>  
<script>  
var app = angular.module("myapp",[]);  
app.controller("usercontroller", function($scope, $http){  
$scope.displayData = function(){  
alert ("s");
$http.get("data.php",$scope.names = response ).success(function(response){});  
}  
});  
</script>  

更改您的函数体并获取对此的请求

$http.get("data.php").success(function(response){
$scope.names = response;
});  

最新更新