I did a function that updates a table and a graph with setTimeout () and it works perfectly.
The problem is that there are occasions (not always) that if I'm on another screen, I see ajax calls (I've reviewed it in the requests, on the networks screen, in the Google Chrome Developer option) that are in this function (without calling the function) and what I'm seeing disappears and I get the whole PHP response in case of not finding information in PHP.
This is my code.
var cronometro;
$(document).on('change','#select_export', function go_async()
{
clearTimeout(cronometro);
$("#answer").remove();
$('#export_graph').html("");
var exporte = $('select[name=select_export]').val();
var exporte_graph = $('select[name=select_export]').val();
$.ajax(
{
url:"phpFiles/finExport.php",
method:"POST",
data:{exporte:exporte},
success:function(data)
{
$('#export_respose').html(data);
$.ajax(
{
url:"phpFiles/finExport_chart.php",
method:"POST",
data:{exporte:exporte_graph},
success:function(datas)
{
var script=document.createElement('script');
script.type='text/javascript';
script.id='answer';
$("body").append(script);
$('#answer').html(datas);
$("#trigger").click();
}
});
}
});
cronometro = setTimeout(function(){ go_async(); }, 30000);
});
I've put clearTimeout(cronometro);
to all my functions but still doing those things.