【问题标题】:jquery page not reloading (location.reload)jquery 页面未重新加载(location.reload)
【发布时间】:2015-08-29 01:32:53
【问题描述】:

从查询回显成功消息后,我的页面没有刷新。我已经尝试过 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";
        }       
}

【问题讨论】:

  • True 只是断言页面不应该从缓存中加载。
  • 感谢您告诉我
  • 根据您的浏览控制台,页面上是否还有其他 javascript 错误?
  • 如果有任何错误,请查看控制台。
  • 控制台没有错误

标签: javascript php jquery


【解决方案1】:

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

window.location.href=window.location.href

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

【讨论】:

  • 我试过了,在 post 函数之外使用 if 语句,结果相同。
【解决方案2】:
try this :

  location.reload();

你也可以调用函数:

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

然后放在那里:

reload();

【讨论】:

    猜你喜欢
    • 2016-04-10
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 2014-08-26
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多