I checked several posts but I couldn't make it work. Here where I came so far:
myApp.controller('customersCtrl', function($scope, $http, $timeout) {
var polling = function() {
var value = $http({
method: 'GET',
url: 'poll.php'
});
value.success(function(data, status, headers, config) {
$scope.records = data;
});
$timeout(function() {
polling();
}, 3000);
};
polling();
});
<?php
$db = new mysqli('fdb4.freehostingeu.com', '1584066_users', '*******', '1584066_users');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$db->set_charset("utf8");
if(!$result = $db->query("SELECT * FROM mtp ORDER BY date DESC")){
die('There was an error running the query [' . $db->error . ']');
}
while($row = mysqli_fetch_assoc($result)){
$row["date"] = strtotime($row["date"]) * 1000;
$records[] = $row;
}
print( json_encode($records));
$result->free();
$db->close();
?>
It works on the first poll();
call but doesn't refresh if the SQL table updated from outside.
EDIT: I tried it by chance and somehow POST method worked in my case.