[英]How to redirect to dashboard if the login is correct
here validating login details. 在这里验证登录详细信息。 but how do i redirect to dashboard if login credentials are correct.
但是,如果登录凭据正确,我如何重定向到仪表板。 And how do i avoid page refresh on submit with getting all the data from the form
以及如何避免从表单中获取所有数据而在提交时刷新页面
if(db.email == logEmail.value && db.password == logPass.value){
window.location = '../html/dashboard';
}else{
console.log('username and password incorrect');
}
}
Since you did not post your entire form I would assume it goes something like this: 由于您没有发布整个表单,因此我认为它是这样的:
<!DOCTYPE html>
<html>
<head>
<script>
function sampleLogin() {
if (/* some condition false*/) {
alert("cannot Submit form");
window.location = ''; // your desired location
return false; //<-- return false you can redirect here if you want
}
}
</script>
</head>
<body>
<form action="someUrl" method="post" onsubmit="sampleLogin()">
User:
<input type="text" id="user" name="user">
<br>
<br> Pass:
<input type="password" id="password" name="password">
<br>
<br>
<button>Submit</button>
</form>
</body>
</html>
If your submit method returns false it does not redirect or submits and you can use this to perform your own logic of redirecting. 如果您的Submit方法返回false,则它不会重定向或提交,您可以使用它执行自己的重定向逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.