迫切需要另一双眼睛。此表单提交在第一次提交时完美运行。但除非我再次重新加载页面,否则它将失败。我觉得我已经检查了所有内容,无论js中的内容如何,表单值都会重置,但由于某种原因,它们不会在第二篇文章中将其置于Request负载中。非常感谢任何帮助。
$scope.submitLogin = function(data) {
var form = $scope.login;
$scope.formerror = '';
$scope.success = '';
if (form.username.length > 0 &&
form.password.length > 0) {
console.log(form.username);
console.log(form.password);
$http.post('/login', form)
.success(function(data) {
$scope.success = data['res'];
$scope.login = [];
window.scrollTo(0, 0);
})
.error(function(data) {
$scope.formerror = data;
});
} else {
$scope.formerror = "something went wrong. Try again.";
}
//$scope.form = new Array({'error':'test', 'msg':''});
}
<form id="login-form" ng-submit="submitLogin()" role="form">
<label for="login_user">username: </label>
<input id="login_user" ng-model="login.username" type="text" name="username" class="form-control" placeholder="username">
<label for="login_password">password: </label>
<input id="login_password" ng-model="login.password" type="password" name="password" class="form-control" placeholder="password">
<input class="btn btn-primary" type="submit" class="btn btn-success btn-send" value="login">
</form>