I have a controller declared and I was loading the data from a json file. THat was working fine, so I decided to create a database and a php file to do a select and retrieve the data from the table I am storing it.
The data from php is retrieved on json, this is my code on php:
<?php
$con = mysqli_connect("127.0.0.1", "root", "", "peopledir");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM people");
$rows = array();
while ($row = mysqli_fetch_array($result)) {
$rows[] = $row;
}
print json_encode($rows);
mysqli_close($con);
?>
It retrieves this:
[{"0":"1","id":"1","1":"Santiago","name":"Santiago"}]
My controller is:
'use strict';
/* Controllers */
var myApp = angular.module('myApp');
myApp.controller('PeopleController', function($scope, $http) {
$http.get('http://localhost').success(function(data) {
$scope.peoples = data;
});
});
But it is not showing any data on the frontend.
To be clear, if I paste the data to a json file, exactly as php is showing it, I can see the user Santiago on the page, but with above code, reading directly from http://localhost
, I can not see anything.
Thanks