I have the following code
$(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.
});
It works beautifully. This loads the page every 3000 milliseconds, but it does it forever, meaning that if someone leaves their browser open, my server storage gets used up a lot since it runs a MySQL query on that other page.
How can I limit this so it calls it every 3000 seconds, but after 10 minutes (or after X loads) it stops (until page is refreshed/changed)?
I'm trying one of the answers, but it's not working. I'm a noob when it comes to AJAX, am I doing it correctly?
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++;
});