私はログインフォームをしようとしています。私はangularjsのng-submitを使用しています。送信ボタンをクリックすると、urlを変更せずにpostメソッドをサーバーで呼び出すようにします。投稿を送信して、URLを変更せずに表現してください。
expressのpost
には、応答するURLが必要です。ログイン画面のURLがhttp://localhost:2000/login
で、送信がクリックされた場合、post
が同じURLの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