I have a form with the tag ng-submit="login()
The function gets called fine in javascript.
function LoginForm($scope, $http)
{
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
$scope.email = "[email protected]";
$scope.password = "1234";
$scope.login = function()
{
data = {
'email' : $scope.email,
'password' : $scope.password
};
$http.post('resources/curl.php', data)
.success(function(data, status, headers, config)
{
console.log(status + ' - ' + data);
})
.error(function(data, status, headers, config)
{
console.log('error');
});
}
}
I am getting a 200 OK response back from the PHP file, however, the returned data is saying that email and password are undefined. This is all the php I have
<?php
$email = $_POST['email'];
$pass = $_POST['password'];
echo $email;
?>
Any idea why I am getting undefined POST values?
EDIT
I wanted to point out since this seems to be a popular question (yet it is old), .success and .error have been deprecated and you should use .then as @James Gentes pointed out in the commments
$http?Form-Datait says{"email":"[email protected]","password":"1234"}print_r($_POST);and then tryjson_decode()on the right indexecho 'test';works fine. I am certainly pointing to the right file