I am trying to build an AngularJS based front-end to a PHP back-end base application. I build the JSON object with a PHP & MySQL query. The JSON is exported correctly and the data is shown if i use the objet inline with an ng-init
directive. But when I mount the Json.php
file on the controller something seem to be wrong because I don't see any data.
This is the link to the example, Here the controller is beneath the </body>
tag.
This is the main page
<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">
this is the controller:
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');
});
}]);
Maybe the module should be on another page? I asked this question earlier. Maybe it can help somehow.
json.php
is giving a 500. – Josiah Keller Jan 22 '16 at 14:44