[英]Jquery refresh the page after success
How do I refresh the page after ajax call success. ajax调用成功后如何刷新页面。 The page doesn't refresh even thought I have put window.location.reload(true)
.即使我已经放置了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);
}
});
});
$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']);
Please try below code :-请尝试以下代码:-
location.reload();
Edited :-编辑:-
success : function(data) {
alert(data);
location.reload();
}
Other ways :-其他方式:-
location.reload()
history.go(0)
location.href = location.href
location.href = location.pathname
location.replace(location.pathname)
location.reload(false)
Please have a look on below link :- There are 534 other ways to reload the page with JavaScript :-请查看以下链接:- 还有 534 种其他方法可以使用 JavaScript 重新加载页面:-
http://www.phpied.com/files/location-location/location-location.html http://www.phpied.com/files/location-location/location-location.html
试试这个:
location.reload(true);
The next statement wont execute unless you click Ok on alert().除非您在 alert() 上单击 Ok,否则下一条语句不会执行。 So use console.log(data) instead.所以改用 console.log(data) 。
success : function(data) {
console.log(data);
window.location.href=window.location.href;
}
In your ajax success callback do this:在您的 ajax 成功回调中执行以下操作:
success: function(response){
setTimeout(function(){
location.reload()
}, 5000);
}
As you want to reload the page after 5 seconds, then you need to have a timeout as suggested in the answer.由于您想在 5 秒后重新加载页面,因此您需要按照答案中的建议设置超时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.