我正在嘗試爲PHP後端基礎應用程序構建一個基於AngularJS的前端。我使用PHP & MySQL查詢構建JSON對象。 JSON被正確導出,並且如果我使用與ng-init
指令內聯的objet,則會顯示數據。但是,當我在控制器上安裝Json.php
文件時,似乎出現錯誤,因爲我沒有看到任何數據。從PHP獲取JSON與PHP的AngularJS沒有顯示在控制器上
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. –
對不起,我對服務器進行了更新,這是新的鏈接http://seveloff.com/survey/json.php,這是到頁面http:// seveloff的新鏈接。 com/survey/results.php – DavSev