I've implemented the code below, it runs the page every X Seconds, but it never stops, it gets in an infinite loop.
I would like to make the code stop running when:
if (track_click >= total_pages - 1) {}
But I do not know what code to put to stop script execution.
<script type="text/javascript">
var track_click = 0;
var total_pages = <?php echo $total_pages; ?>;
$('#animation_image').load("exportar_4_detalhe.php", {'page': track_click}, function() {
track_click++;
});
var funcaoCounter = 0;
var funcaoTimer = setInterval(function(){
funcaoCounter++;
$('.load_more').hide();
$('.animation_image').show();
if (track_click <= total_pages){
$.post('exportar_4_detalhe.php', {'page': track_click}, function(data) {
$(".load_more").hide();
$("#results").append(data);
var resultado = ( track_click /total_pages ) * 100;
// document.title = track_click + " de " + total_pages;
var new_num = resultado.toFixed(2);
var new_num = new_num + "%";
document.title = new_num;
$('.porcentagem').text(new_num);
$("html, body").animate({scrollTop: $("#animation_image").offset().top}, 500);
$('.animation_image').hide();
track_click++;
}).fail(function(xhr, ajaxOptions, thrownError) {
alert(thrownError);
$(".load_more").show();
$('.animation_image').hide();
});
if (track_click >= total_pages - 1)
{
$('.animation_image').hide();
clearInterval(funcaoTimer);
alert('Todos os Registros forma Exibidos!');
}
}
}, 1000);
</script>