简体   繁体   中英

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.

Now what i want to do is when the message is "correct email" the user should be redirected to for example "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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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