Right now I have a basic post request using the $http service in angular. I'm seeing everything find in console.log with a status of 200 (successful), but in PHP no luck. I've tried using JSON_decode, I've tried the $_POST (var_dump) no luck. Please assist if you can think of a solution.
app.js
var postData={
firstName:'something',
lastName:'here'
};
postData=JSON.stringify(postData);
$http({method:'POST',url:'sendmail.php',data:postData,headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
.success(function (data,status,headers,config) {
console.log('Success' + data);
})
.error(function (data, status,headers,config) {
// uh oh
console.log('error' + status + data);
});
sendmail.php
$args = json_decode(file_get_contents("php://input"));
echo $args->firstName;
In my php file I am getting the following error.
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/my-new-project/sendmail.php on line 3
however, in my console.log I am getting:
Successsomething
Also, I have a live site with the same problem.
Just to reiterate no matter what I do, (add headers, JSON decode) PHP array remains empty.
$http
automatically stringifies your objects. Skip that step in your code