Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
让jQuery等待_Jquery_Ajax_Delay - Fatal编程技术网

让jQuery等待

让jQuery等待,jquery,ajax,delay,Jquery,Ajax,Delay,我的Ajax中有以下代码,它在时间用完时执行页面重新加载功能 if(time<=0) { $(".time_remaining").html("Reloading the page now."); refresh(); } 有时代码不更新,而是刷新,但内容与以前相同(每次内容肯定都会更改)。我认为这可能是由于index.php运行速度不够快,但Ajax正在匆忙执行 $("#current_body").html(data); 线路。我可以让Ajax在发送数据和打印结

我的Ajax中有以下代码,它在时间用完时执行页面重新加载功能

if(time<=0)
{
    $(".time_remaining").html("Reloading the page now.");
    refresh();
}
有时代码不更新,而是刷新,但内容与以前相同(每次内容肯定都会更改)。我认为这可能是由于index.php运行速度不够快,但Ajax正在匆忙执行

 $("#current_body").html(data); 

线路。我可以让Ajax在发送数据和打印结果之间延迟吗?

只有在服务器返回有效响应后,
成功
回调才会触发

 $("#current_body").html(data); // this will be executed when
                                // the "slow" server finishes it's work

因此,这与服务器速度无关。

成功函数将等待ajax请求完成加载。您遇到的问题可能与缓存有关。在您的选项中,设置cache:false,它应该是ok:)


/**编辑以使其更有意义**/

尝试将index.php更新为“index.php?t=“+(new Date()).getTime(),以查看是否会破坏任何可能导致其返回相同内容的缓存。

嗯?index.php“工作速度不够快”是什么意思?
success
回调在页面完全下载之前不会运行。请将其排序,谢谢。这与代码中的一个bug有关,该bug实际上没有改变其中一个阶段(最后一个阶段)的内容。谢谢你给我灌输了一些道理。卡什:false会帮你的。这不是这里的问题
 $("#current_body").html(data); // this will be executed when
                                // the "slow" server finishes it's work