无法使用AngularJS显示请求中的数据

时间:2016-12-30 09:25:28

标签: sql angularjs

我正在尝试显示从名为student的SQL表中获取的数据。我有JSON对象包含使用PHP文件从表中检索的数据。但我无法使用AngularJS在我的HTML文件中显示数据。 这是我的myScript.js代码

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文件的响应也是

形式的json对象
[{"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"}]         

1 个答案:

答案 0 :(得分:0)

您需要使用请求结果中的数据对象:

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