Very new with AngularJS, I'm sure it's something simple I'm doing wrong but I cannot figure it out. All I'm trying to do is log the incoming POST from Angular, using PHP.
AngularJS function:
$scope.addTask = function() {
$http.post('process.php', { newTask: $scope.newTask });
$scope.newTask = '';
};
process.php:
if (isset($_POST['newTask'])) {
createLog('test');
}
function createLog ($str) {
$file = 'log.txt';
$str .= "
";
file_put_contents($file, $str, FILE_APPEND | LOCK_EX);
}
If you are sending in a POST to PHP from angular, you need to retrieve it a bit differently in your backend. As noted by @charlietfl, the $_POST is empty. I have been out of the PHP game for a while but this should work for you.
$data = file_get_contents("php://input");
$request = json_decode($data);