I use Jquery to make an Ajax request. The server returns Json object with value "true or false" like this:
return Json(new { success = false, JsonRe
location.reload();
You can use the reload
function in your if
condition for success and the page will reload after the condition is successful.
var val = $.parseJSON(data);
if(val.success == true)
{
setTimeout(function(){ location.reload(); }, 5000);
}
if(success == true)
{
//For wait 5 seconds
setTimeout(function()
{
location.reload(); //Refresh page
}, 5000);
}
In your ajax success callback do this:
success: function(data){
if(data.success == true){ // if true (1)
setTimeout(function(){// wait for 5 secs(2)
location.reload(); // then reload the page.(3)
}, 5000);
}
}
As you want to reload the page after 5 seconds, then you need to have a timeout as suggested in the answer.
I prefer this way
Using ajaxStop
+ setInterval
,, this will refresh the page after any XHR[ajax] request in the same page
$(document).ajaxStop(function() {
setInterval(function() {
location.reload();
}, 3000);
});
$.ajax("youurl", function(data){
if (data.success == true)
setTimeout(function(){window.location = window.location}, 5000);
})
)