简体   繁体   English

如果登录正确,如何重定向到仪表板

[英]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.

相关问题 如何使用 ReactJS 将登录页面重定向到仪表板? - How to redirect login page to dashboard using ReactJS? 登录成功后如何使用ReactJS重定向到仪表板? - How to redirect after login success to dashboard using ReactJS? 在Vue JS中成功登录后如何重定向到仪表板组件页面(登录组件)? - How to redirect to the dashboard component page after login successfully(login component) in vue js? auth0登录Angular后如何重定向到http://localhost:4200/shops/shop1/dashboard - How to redirect to http://localhost:4200/shops/shop1/dashboard after auth0 login in Angular 如果用户已登录并且在所有其他情况下显示公共路由,如何重定向到 /dashboard 公共路由 /login 和 /register? - How to redirect to /dashboard public routes /login and /register if user is logged in and in all other cases show public routes? 使用php将登录用户从登录页面重定向到用户仪表板 - Redirect a logged in user from login page to user dashboard with php AngularJS,登录后将用户重定向到正确的页面 - AngularJS, Redirect user to correct page after login 如果用户使用AngularJS登录,如何重定向到仪表板? - How to redirect to dashboard if user is logged in with AngularJS? 登录后如何重定向 - How to redirect after login 登录重定向后如何重定向到任何 url? - How to redirect to any url after login in redirect?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM