简体   繁体   English

使用ajax登录并重定向

[英]Login and redirect with ajax

i want to redirect to a different page when email and password are right. 当电子邮件和密码正确时,我想重定向到其他页面。 with my script i'm able to either the user has entered the right or wrong email and password. 使用我的脚本,我可以使用户输入正确或错误的电子邮件和密码。 when its right it tells "correct email" and when it's wrong it tells "wrong email or password" in the "message" div. 当它正确时,它会告诉“正确的电子邮件”,当它错误时,它会在“消息” div中告诉“错误的电子邮件或密码”。

Now what i want to do is when the message is "correct email" the user should be redirected to for example "inside.php". 现在,我想做的是,当消息为“正确的电子邮件”时,应将用户重定向到例如“ inside.php”。 what script do i add to make it work? 我要添加什么脚本才能使其正常工作?

$(document).ready(function(){
    $("form").on('submit',function(event){
        event.preventDefault();

        data = $(this).serialize();
        $.ajax({
        type: "POST",
        url: "login.php",
        data: data
        }).success(function(msg) {
   $('#message').html(msg);


        });
    });
});
$(document).ready(function(){
    $("form").on('submit',function(event){
        event.preventDefault();

        data = $(this).serialize();
        $.ajax({
        type: "POST",
        url: "login.php",
        data: data
        }).success(function(msg) {

    window.location.href = 'desired_url' ;


        });
    });
});

on success , use window.location.href = 'desired_url'; 成功时,使用window.location.href ='desired_url';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM