0
我試圖顯示從名爲student的SQL表中獲取的數據。我有JSON對象包含使用PHP文件從表中檢索的數據。但我無法使用AngularJS在我的HTML文件中顯示數據。 這是我的myScript.js代碼無法使用AngularJS顯示來自請求的數據
var myApp = angular.module("myModule",[])
.controller("myController",function($scope,$http)
{
getData();
function getData(){
$http.post("php/display.php").success(function(data)
{
$scope.student=data.data;
});
}
});
這是我的index.html文件
<html ng-app="myModule">
<head>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="myscript.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body ng-controller="myController">
<table>
<tr>
<th>ID</th>
<th>NAME</th>
<th>CITY</th>
</tr>
<tr ng-repeat="stud in student">
<td>{{stud.id}}</td>
<td>{{stud.name}}</td>
<td>{{stud.city}}</td>
</tr>
</table>
</body>
</html>
另外我的文件Display.php的響應的格式爲
[{"Id":"1","name":"Swapnil","city":"Nanded"},
{"Id":"2","name":"Swap","city":"Nanded"},
{"Id":"3","name":"Swapn","city":"Nanded"},
{"Id":"4","name":"Swapni","city":"Nanded"},
{"Id":"5","name":"Swap","city":"Parbhani"}]
嘗試'$ scope.student = data.data;'它會工作。 –
驗證你能夠獲取成功的數據方法,如果得到然後分享$ scope.student值 –
我試圖$ scope.student = data.data但仍然無法顯示結果集。 – SwapRenge