【发布时间】:2016-01-22 14:33:06
【问题描述】:
我正在尝试为 PHP 后端基础应用程序构建基于 AngularJS 的前端。我使用 PHP & MySQL 查询构建 JSON 对象。如果我使用带有ng-init 指令的内联对象,JSON 会正确导出并显示数据。但是当我在控制器上挂载Json.php 文件时,似乎出现了问题,因为我没有看到任何数据。
This is 示例链接,此处控制器位于</body>标签下方。
这是主页
<html ng-app="myApp">
<head>
<title></title>
</head>
<body>
<div style="direction: ltr">
</div>
<h1>תוצאות שאלון</h1>
<div class="table-responsive" ng-controller="ContentCtrl">
<table class="table" id="results" >
<thead>
<tr>
<th>id</th>
<th>q1</th>
<th>q2</th>
<th>q3</th>
<th>textarea</th>
<th>phone</th>
<th>name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="answer in answers.data">
<td>{{answer.id}}</td>
<td>{{answer.q1}}</td>
<td>{{answer.q2}}</td>
<td>{{answer.q3}}</td>
<td>{{answer.textarea}}</td>
<td>{{answer.phone}}</td>
<td>{{answer.name}}</td>
</tr>
<?php/*
$table = new Results();
$table->allrows();
*/?>
</tbody>
</table>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script type="text/javascript" src="js/js.js"></script>
<!--<script src="js/controllers.js"></script>-->
<script type="text/javascript">
这是控制器:
var myApp = angular.module('myApp', []);
myApp.controller('ContentCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get('json.php')
.success(function(data) {
$scope.answers = data;
console.log('test');
});
}]);
也许模块应该在另一个页面上? 我之前问过this question。也许它可以以某种方式提供帮助。
【问题讨论】:
-
在您链接的示例页面上,
json.php给出了 500。 -
抱歉,我更换了服务器,这是新链接seveloff.com/survey/json.php,这是指向页面seveloff.com/survey/results.php的新链接
标签: php angularjs json controller