anon anon - 1 month ago 11
Ajax Question

Jquery refresh the page after success

How do I refresh the page after ajax call success. The page doesn't refresh even thought I have put

window.location.reload(true)
. It only displays the echo message but doesn't refresh it

$("#update-btn").click(function() {
var token = document.getElementById('tokenAmount').value;; //Place the token here
var master = currentUserID;
var lastUser = lastNode.info.id;
$.ajax({
type : "POST",
url : "update.php",
data : {'master': master,
'token' : token,
'user_id': lastUser
},
success : function(data) {
alert(data);
window.location.reload(true);
}
});
});


update.php



$master=$_POST['master'];
$user = $_POST['user_id'];
$token = $_POST['token'];

if(condition)
{
$result = $MySQLi_CON->query($secondToken);
if($result == false)
$response['msg'] = "Not Enough";
else
{
$response['msg'] = "Successful";
}
}

else
{
$response['msg'] = "Not enough";
}
echo json_encode($response['msg']);

Answer

The next statement wont execute unless you click Ok on alert(). So use console.log(data) instead.

success : function(data) {
                console.log(data);
                window.location.href=window.location.href;
            }
Comments