I'm having a simple problem that I cannot seem to resolve. I'm trying to return a simple set of data from mysql database using angular/ajax and php. The problem is nothing populates in the HTML. No errors in debugger. Here is my code.
HTML:
<?php
include("includes/header.php");
?>
<body ng-app="testapp">
<div ng-ctrl="HomeController">
<input type="text" ng-model="name">
<p>{{name}}</p>
<ul ng-repeat="user in users">
<li>{{user.fname user.lname}}</li>
</ul>
</div>
<script type="text/javascript" src="angular/testapp.js"></script>
<script type="text/javascript" src="angular/TestController.js"></script>
</body>
<?php
include("includes/footer.php");
?>
ANGULAR/AJAX
angular.module("testapp").controller("TestController", function($scope, $http){
$scope.name = "";
$http({
method: "POST",
url: "../includes/getUsers.php"
}).success(function(data){
$scope.users = data;
});
});
Finally PHP getUsers.php:
include("connection.php");
$query = "SELECT fname, lname FROM user"
$rows = $db->query($query);
$data = array();
while ($row = $rows->fetchAll(PDO:FETCH_ASSOC)) {
$data[] = $row;
}
echo json_encode($data);
POST?connection.phpcode