2016-12-30 41 views
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"}]   
+0

嘗試'$ scope.student = data.data;'它會工作。 –

+0

驗證你能夠獲取成功的數據方法,如果得到然後分享$ scope.student值 –

+0

我試圖$ scope.student = data.data但仍然無法顯示結果集。 – SwapRenge

回答

0

JSON對象您需要使用請求中的數據對象結果

$http.post("php/display.php").success(function(result) { 
    $scope.student = result.data;           
}); 
相關問題