Javascript AngularJS:从php脚本获取JSON

Javascript AngularJS:从php脚本获取JSON,javascript,php,angularjs,json,Javascript,Php,Angularjs,Json,我正在W3学校尝试以下AngularJS教程 我更改了脚本,使其与我的一个php脚本一起工作: <!DOCTYPE html> <html > <style> table, th , td { border: 1px solid grey; border-collapse: collapse; padding: 5px; } table tr:nth-child(odd) { background-color: #f1f1f1; } tab

我正在W3学校尝试以下AngularJS教程

我更改了脚本,使其与我的一个php脚本一起工作:

<!DOCTYPE html>
<html >
<style>
table, th , td  {
  border: 1px solid grey;
  border-collapse: collapse;
  padding: 5px;
}
table tr:nth-child(odd) {
  background-color: #f1f1f1;
}
table tr:nth-child(even) {
  background-color: #ffffff;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="customersCtrl">

<table>
  <tr ng-repeat="x in names">
    <td>{{ x.name }}</td>
  </tr>
</table>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
       $http.get("http://wirtschaftsinformatik.web2page.ch/selectModule.php")
//my url
       .then(function (response) {$scope.names = response.data.records;});
    });
    </script>

    </body>
    </html>
HTML

 <div ng-controller="listController">
    <table>
      <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Time</th>
      </tr>
      <tr ng-repeat="person in names">
        <td>{{person.id}}</td>
        <td>{{person.name}}</td>
        <td>{{person.timestamp}}</td>
      </tr>
    </table>
  </div>

身份证件
名称
时间
{{person.id}
{{person.name}
{{person.timestamp}

HTML

 <div ng-controller="listController">
    <table>
      <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Time</th>
      </tr>
      <tr ng-repeat="person in names">
        <td>{{person.id}}</td>
        <td>{{person.name}}</td>
        <td>{{person.timestamp}}</td>
      </tr>
    </table>
  </div>

身份证件
名称
时间
{{person.id}
{{person.name}
{{person.timestamp}

返回的json没有records属性,下面是一个简单的解决方案:

echo json_encode(["records"=>$jsonArray], JSON_UNESCAPED_UNICODE); 

返回的json没有records属性,下面是一个简单的解决方案:

echo json_encode(["records"=>$jsonArray], JSON_UNESCAPED_UNICODE); 


什么不起作用?表格不显示记录?是的,表格不显示记录。您可以过帐吗json@Sajeetharan我加上了。什么不起作用?表格不显示记录?是的,表格不显示记录。您可以过帐吗json@Sajeetharan我加的,非常感谢!它的作品很棒!我看到您创建了一个JSON文件。有没有办法直接从php脚本获取它?Iyes您可以使用get-http调用并执行相同的操作。如果答案对你有帮助,请记为答案谢谢!你是什么意思?我把它放进去了,但它不起作用。@EroStefano您不能直接从angular获取数据,您需要在php中这样做。查看此链接非常感谢!它的作品很棒!我看到您创建了一个JSON文件。有没有办法直接从php脚本获取它?Iyes您可以使用get-http调用并执行相同的操作。如果答案对你有帮助,请记为答案谢谢!你是什么意思?我把它放进去了,但它不起作用。@EroStefano您不能直接从angular获取数据,您需要在php中这样做。检查此链接谢谢,但是仍然缺少一些内容,因为它仍然无法工作。我创建了一个新文件:谢谢,但是仍然缺少一些东西,因为它仍然不能工作。我创建一个新文件: