What i did was to put all the code into a set interval function, in this way I will render a location every 5 seconds
The base
setInterval(() => {
//code to execute
}, 5000);
Applying to my div
setInterval(() => {
console.log("interval")
$.ajax({
url: window.location.pathname,
async: false,
type: 'POST',
data: {
'action': 'graph_ubicacion',
'id': id
},
dataType: 'json',
}).done(function (data) {
//console.log("DEBUG 83 === ", data)
if (!data.hasOwnProperty('error')) {
//Proceso cuando se elije una ubicacion (después de tener una respuesta
dataCharArray = [
['Nombre', 'X', 'Y', 'Tipo'],
];
if (data.hasOwnProperty('todas')) {
data['todas'].forEach(function (elemento) {
dataCharArray[dataCharArray.length] = elemento;
//console.log("DEBUG 91 === ", elemento)
});
}
if (data.hasOwnProperty('target')) {
data['target'].forEach(function (elemento) {
dataCharArray[dataCharArray.length] = elemento;
console.log("DEBUG 102 === ", elemento, "\n")
console.log("DEBUG 102 === ", elemento[0], "\n")
console.log("DEBUG 102 === ", elemento[1], "\n")
console.log("DEBUG 102 === ", elemento[2], "\n")
console.log("DEBUG 102 === ", elemento[3], "\n")
});
}
if(data['todas'].length > 0 && data['target'].length > 0){
google.charts.load('current', {
'packages': ['corechart']
}
);
google.charts.setOnLoadCallback(drawSeriesChart);
}else{
if(data['todas'].length === 0 && data['target'].length === 0){
//MensajeAlerta("No hay Datos para mostrar");
console.log("No hay datos para mostrar")
}else{
if(data['todas'].length === 0){
MensajeAlerta("No hay Balizas para mostrar");
}
if(data['target'].length === 0){
MensajeAlerta("No hay Historial de datos de Pulseras para mostrar.");
}
}
}
return false;
} else {
MensajeError(data['error']);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
MensajeError(textStatus + ': ' + errorThrown);
}).always(function (data) {
})
}, 5000);