I am making an AngularJS application with a PHP backend, and am I attempting to persist some data to write into a database. I came across a hurdle I am attempting to jump over.
When I do a var_export($_POST)
I get a blank (empty) array as a return.
However, when I do a $return json_decode(file_get_contents("php://input"), false);
I get a full array with the values I expect?
How can I use the $_POST variable with the below?
My AngularJS code:
$scope.testPostRequest = function() {
$http({
method: 'POST',
url: 'requestHandler.php',
data: JSON.stringify($scope.scores), // pass in data as strings
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
} // set the headers so angular passing info as form data (not request payload)
}).success(function(data) {
console.log(data);
if (!data.success) {
// if not successful, bind errors to error variables
} else {
// if successful, bind success message to message
$scope.message = data.message;
}
});
}
My entire PHP code (I just comment out the return I am interested in).
//$data = json_decode(file_get_contents("php://input"), false);
//return var_export($data);
return var_export($_POST);