我有一张标签是ng-submit="login()
的表格
该函数在javascript中可以很好地调用.
function LoginForm($scope, $http)
{
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
$scope.email = "fsdg@sdf.com";
$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');
});
}
}
我收到PHP文件返回的200OK响应,然而,返回的数据显示email
和password
是未定义的.这是我所有的php.
<?php
$email = $_POST['email'];
$pass = $_POST['password'];
echo $email;
?>
知道我为什么会得到未定义的POST
个值吗?
EDIT
我想指出的是,因为这似乎是一个流行的问题(但它已经过时了),.success
和.error
已经被弃用,你应该使用.then
,正如@James Gentes在commments中指出的那样