0

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";
        }       
}
machinehead115
  • 1,647
  • 10
  • 20
kye
  • 2,166
  • 3
  • 27
  • 41

2 Answers2

0

It's possible that your .reload() is POSTing 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()

Community
  • 1
  • 1
Will
  • 4,075
  • 1
  • 17
  • 28
0
try this :

  location.reload();

also you can call function :

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

and put there :

reload();
Mohammed Elhag
  • 4,272
  • 1
  • 10
  • 18