我有以下代碼: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')。 –
好的檢查!謝謝! –