I have the following code in my Ajax, which executes a page reload function when time runs out.
if(time<=0)
{
$(".time_remaining").html("Reloading the page now.");
refresh();
}
refresh() is as follows:
function refresh() {
$.ajax({
type: 'POST',
url: 'index.php',
data: 'refresh=true',
timeout: 0,
success: function(data) {
$("#current_body").html(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$("#notice_div").html('Error contacting server. Retrying in 60 seconds.');
window.setTimeout(update, 60000);
}
});
};
Sometimes the code doesn’t update, rather it refreshes, but with the same content as before (the content definitely changes every time). I think it might be due to index.php not working quickly enough, but the Ajax is rushing to execute the
$("#current_body").html(data);
line. Can I make it so the Ajax delays itself between sending the data and printing the result?
The
successcallback will fire only after the server returned a valid response.So no, it has nothing to do with the server speed.