Reputation: 1477
Im truing to send a email but for some reason cant send the data in my http post, in my php var_dump data says array dont have any proeprties, i dont receive the data in my php script.
network sent data:
My controler code:
$http({
method: 'POST',
url: 'php/admin-mail.php',
data: claimDataService.get(),
headers : {'Content-Type': 'application/x-www-form-urlencoded'} ,
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log("sucess");
console.log(response);
}, function errorCallback(response) {
console.log("errors");
console.log(response);
});
My Service:
var claimDataService = angular.module('claimDataService', []);
claimDataService.factory('claimDataService', function() {
var claimData = {}
function set(data) {
claimData = data;
}
function get() {
return claimData;
}
return {
set: set,
get: get,
}
});
admin-mail.php:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
return $_POST['myData'];
}
Upvotes: 1
Views: 236
Reputation: 1407
I believe I've found your problem, if you're trying to your data as JSON you must have
headers : { 'Content-Type': 'application/json' }
Then have your PHP script to get the input
$data = json_decode(file_get_contents('php://input'), true);
Upvotes: 2