查询返回成功消息后,我的页面不会刷新。我尝试过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";
}
}
您的.reload()
可能在页面重新加载时再次出现POST
,这可能会导致循环。尝试:
window.location.href=window.location.href
SO相关问题:window.location.href=window.location.htm和window.location.reload((之间的差异
try this :
location.reload();
也可以调用函数:
function reload(){location.reload();}
并放在那里:
reload();