admin管理员组文章数量:1415467
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']);
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']);
Share
Improve this question
edited Oct 18, 2016 at 7:26
anon
asked Oct 18, 2016 at 7:12
anonanon
31 gold badge1 silver badge6 bronze badges
7
- use a flag session for this status – Suraj Commented Oct 18, 2016 at 7:21
-
I see a
}
in more at the line 15 of 'update.php'. Check it please – The Dude Commented Oct 18, 2016 at 7:24 - alert(data); what data are you getting in alert? – Kamran Khatti Commented Oct 18, 2016 at 7:29
- echo message alert – anon Commented Oct 18, 2016 at 7:38
- I mean it alerts 'Successful' or 'Not enough' ? – Kamran Khatti Commented Oct 18, 2016 at 7:44
5 Answers
Reset to default 1Please 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 :-
http://www.phpied./files/location-location/location-location.html
.ajaxStop()
callback executes when all AJAX call pleted. This is a best place to put your handler.
$(document).ajaxStop(function(){
window.location.reload();
});
The source is from here
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;
}
Try this:
location.reload(true);
In your ajax success callback do this:
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.
本文标签: javascriptJquery refresh the page after successStack Overflow
版权声明:本文标题:javascript - Jquery refresh the page after success - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745171554a2646005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论