jquery页面没有重新加载(location.reload)

时间:2015-08-29 01:32:54

标签: javascript php jquery

从查询中回显成功消息后,我的页面未刷新。我已尝试过location.reload(),location.reload(true),甚至尝试使用“loginFunction.php”页面中的标题重定向,但似乎没有任何效果。

JQuery的

if ($.trim(user) != '' && password != '') {
    $.post('includes/loginFunction.php', {
        userName: user,
        uPassword: password
    }, function(data) {
        var result = data;

        if (data !== "success") {
            $('#uNameE').text(data);
        } else {
            window.location.reload(true);
        }
    });
}

PHP

require_once('dbopen.php');
    if(isset($_POST['userName']) === true && empty ($_POST['userName']) === false ){
        $userName = $_POST["userName"];
        $userPass = $_POST["uPassword"];

        $query = $conn->query("SELECT * FROM members WHERE userN = '$userName' AND password = '$userPass'");
        $num = $query->num_rows;

        if($num != 0 ){ 
            $_SESSION['usernameP'] = $userName;
             //Header not working neither
             //header('location: index.php');
            echo "success";
        }

        else{
            echo "Username or password incorrect";
        }       
}

2 个答案:

答案 0 :(得分:0)

您的.reload()可能会在页面重新加载时再次POST,这可能会导致循环。尝试:

window.location.href=window.location.href

关于SO的相关问题:Difference between window.location.href=window.location.href and window.location.reload()

答案 1 :(得分:0)

try this :

  location.reload();

你也可以调用函数:

  function reload(){location.reload();}

并放在那里:

reload();