我正在嘗試執行登錄表單。我正在使用angularjs的ng-submit。當點擊提交按鈕時,我想要在服務器中調用post方法而不更改url。發送表單請求以表示不更改網址
express的post
需要它響應的url。如果我的登錄屏幕的網址是http://localhost:2000/login
,並且點擊提交時,我希望post
被調用相同的網址http://localhost:2000/login
。
而且我不明白如何使用$http
的url
密鑰。
登錄HTML:
<form ng-controller="loginController" ng-submit="loginFunc()">
<input type="text" name="" ng-model="login">
<input type="password" ng-model="password" name="">
<input type="submit" value="login" name="">
控制器:
.controller('loginController', function($scope, $http) {
$scope.login = ""
$scope.password = "";
$scope.loginArray = [];
$scope.loginFunc() {
$scope.loginArray.push($scope.login);
$scope.loginArray.push($scope.password);
$http({
method: 'POST',
url: 'loginClick',
data: $scope.loginArray
})
}
})
的server.js:
app.get('/login', function(request, response) { //the file sent when /login is requested
response.sendFile(__dirname + "/staticFolder/view/login.html");
})
app.post('/loginCheck', function(request, response) { //call this when submit button is clicked without change in url
console.log(JSON.stringify(request.body) + "req");
})
任何錯誤,你越來越?? – vkstack