My page is not refreshing after the success message is echoed from the query. I've tried location.reload(), location.reload(true) and even tried to redirect using header in 'loginFunction.php' page, but nothing seems to work.
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";
}
}
It's possible that your .reload()
is POST
ing again on page reload which may result in a loop. Try:
window.location.href=window.location.href
Related Question on SO: Difference between window.location.href=window.location.href and window.location.reload()
try this :
location.reload();
also you can call function :
function reload(){location.reload();}
and put there :
reload();