I apologize in advance for what appears to be a duplicate question but I am truly stuck. I am sending login info to a php page which validates the username and password. It works fine in that it says success or failure depending on if the user info exists as shown in the picture. 
What I want to do is send the $user value back to my javascript page and then redirect them to the user page if it returns "ok". I cannot for the life of me figure out how to do it.
Here is my Javascript:
function Userlogin() {
$.post("login.php",
{
username: $("#login_username").val(),
pass: $("#login_password").val()
success: function(user){
alert("Done!");
}
}
},
Here is my PHP:
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['pass']);
echo $username;
$login = mysqli_query($conn, "SELECT * FROM users where username = '$username' and password = '$password'");
$num_rows = mysqli_num_rows($login);
printf("Result set has %d rows.\n", $num_rows);
mysqli_free_result($login);
if ($num_rows == 1) {
echo "Success";
$user = "ok";
} else {
}
echo json_encode($user);
mysqli_close($conn);
Any help would be greatly appreciated. Thanks in advance!