0
$(document).ready(function(){

    $("#login").click(function(){
    $.post($('#loginform').attr("action"), $('#loginform').serializeArray(), function(data) {
                if(data == 'Success'){
                    $(document).ajaxStop(function() { location.reload(true); });
                }else {
                    $('#loginmsg').html(data);
                }
        });
    });
});

Everything is working perfectly fine except the page is not refreshing after a successful submission. How can it be done?

Server-side:

<?php
if (empty($_POST) === false){
    $username = $_POST['username'];
    $password = $_POST['password'];

    if (empty($username) === true || empty($password) === true){
        $errors[] = 'You need to enter a username or password';
    }
    else if (user_exists($username)===false){
        $errors[] = 'We can\'t find that username in our database.';
    }
    else if (user_active($username) === false){
        $errors[] = 'Activate your account.';
    }   else    {
        $login = login($username,$password);
        if ($login === false){
            $errors[] = 'Incorrect combination.';
        } else {
            $_SESSION['user_id'] = $login;
            $errors[] = 'Success';
            exit();
        }
    }
}else {
    $errors[] = 'No data received!';
}
output_errors($errors);
?>
4

3 回答 3

0

You need to wite:

window.location.reload()

OR

window.location.href=window.location.href
于 2013-01-10T09:28:48.950 回答
0

您不需要调用ajaxStop()。将您的成功代码更改为:

if(data == 'Success'){
  location.reload(true);
}
于 2013-01-10T09:39:59.350 回答
0

删除 PHP 中的调用exit()。它阻止它进入output_errors($errors)成功案例,因此您永远不会将Success消息发送给客户端。

于 2013-01-10T10:01:01.590 回答