在 jQuery .load 上设置超时 [英] Set timeout on jQuery .load
本文介绍了在 jQuery .load 上设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在5秒钟后超时,然后显示无法提取页面".但是我不确定如何去做...这就是我到目前为止所得到的...
I want to have a timeout after 5 seconds and then display "Unable to fetch page". But im not sure how to go about it... Heres what I got so far...
$(document).ready(function() {
$('#content').html('<br><br><br><br><img src="load.gif" border="0"><br><br><strong>Generating Link...</strong>');
$("#content").load("ajax.php");
})
推荐答案
var tick = function() {
$("#content").html('Unable to fetch page!');
}
$(document).ready(function() {
var loadTimeout = setTimeout(tick, 5100);
$.ajax({
url: "ajax.php",
timeout: 5000,
success: function(data) {
$("#content").html(data);
clearTimeout(loadTimeout);
}
});
})
这篇关于在 jQuery .load 上设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文