我有以下代码每隔X分钟用AJAX调用一次文件直到Y时间?
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
$('#chatresults').load('includes/chat.php');
}, 3000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
});
它精美的作品。这会每3000毫秒加载一次页面,但它会永久保存,这意味着如果有人将其浏览器打开,我的服务器存储会因为在其他页面上运行MySQL查询而耗尽了很多。
我该如何限制它,以便每3000秒调用它,但是在10分钟后(或X加载后)它会停止(直到页面刷新/更改)?
我正在尝试其中一个答案,但它不工作。谈到AJAX,我是一个noob,我是否正确地做了这件事?
if (counter == 12) {
clearInterval(aux);
}
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
aux = setInterval(function() {
$('#chatresults').load('includes/chat.php');
}, 3000);
counter++;
});
你怎么样,每次循环,您可以添加拍摄,直到它等于10分钟的时间?然后,你可以关闭它。 – SirPython