我有以下代码:AngularJS不发送HTTP POST请求
application.controller('userLoginController', function($scope,$http){
window.document.title = "User Login";
$scope.form = { username: '',password: ''};
$scope.submitLogin = function(){
var config = {
method: 'POST',
url: 'server_app/login.php',
data: {
'username' : $scope.form.password,
'password' : $scope.form.password
}
};
var request = $http(config);
request.then(function (response){
$scope.errorMessage = response.data;
},function(error){
$scope.errorMessage = error.data;
})
}
});
我试图发送POST请求到后端服务器,看起来像:
var_dump($_POST);
与提交我的数据后按钮我应该用$ _POST返回数组。那 Insteed我得到
array (size=0)
empty
我的HTML代码看起来像:
<input placeholder="Login" class="searchProduct" autocomplete="off" name="username" type="text" ng-model="form.username"><br>
<input placeholder="Password" class="searchProduct" autocomplete="off" type="password" name="password" ng-model="form.password"/>
<div class="button" ng-click="submitLogin();">Login</div>
我看不出这里有什么问题..
确实谢谢你,但我没有得到一件事,为什么我需要这样写呢?例如使用Jquery,我只是在做var_dump($ _ POST)? –
当你用formet enctype =“multipart/form-data”发送表单数据时,你可以用$ _POST接收它,因为你发送数据为json,你需要使用file_get_contents('php:// input')。 –
好的检查!谢谢! –