我在我的Ajax中有以下代码,它在时间用完时执行页面重载功能。让jQuery等待
if(time<=0)
{
$(".time_remaining").html("Reloading the page now.");
refresh();
}
刷新()如下:
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);
}
});
};
有时代码没有更新,而它刷新,但具有相同的内容之前(内容每次都肯定是不同的)。我认为这可能是由于index.php工作不够快,但Ajax急于执行
$("#current_body").html(data);
line。我可以做到这一点吗?Ajax会在发送数据和打印结果之间自动延迟?
咦? index.php是什么意思“工作不够快”?直到页面完全下载后,“成功”回调才会运行。 – 2012-02-19 15:38:13