1
I did the implementation of the code below, it rotates the page every X Seconds, but it never stops, it sits in an infinite loop.
I would like to stop the code from running when:
if (track_click >= total_pages - 1) {}
But I don’t know which code to put to stop the 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>
There’s already a line in your code that does that:
clearInterval(funcaoTimer);
. But I haven’t looked at the code in detail, so I can’t tell if this is being used in the right place.– bfavaretto
The worst I’ve seen, for me is in the right place, but it didn’t work, you can help me ?
– Danilo Ramon
I entered thus: clearInterval(function Timer);, but the code still works after I asked to interrupt...
– Danilo Ramon
Maybe the right place to put this (by the way, the whole
if (track_click >= total_pages - 1)
) be shortly after thetrack_click++;
inside the callback of the$.post
.– bfavaretto