AngularJS $http.post() isn't sending data as I expect it to. I try to pass a range of data to a PHP script stored on the same server and when I attempt to echo this back the data always seems to be empty.
My PHP script receiving the data
<?php
$char = $_POST["char"];
$alpha = $_POST["alpha"];
echo $char;
My JS posting to the PHP script
.controller("IndexController", function($scope, $http) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.post("http://jxxxxxxx.xxx/ui/php/curl/index.php", {
char: "a", alpha: 1
}).then(function(response) {
console.log(response);
});
});
In the above instance, response should contain a data property containing the value of $char, in this instance "a".
However, if I
echo "hey";
out of the PHP script, it receives this as the data property when I log the response to the console.
Any idea why my PHP script isn't receiving the POST values correctly?