Hello! I have this code, yes, I make many errors in the code, I'm new using AJAX and Javascript .
var turno_actual = 0;
function desplegarAlerta() {
$(document).ready(function() {
var refreshId = setInterval(function() {
$('#turno').load('./ajax/sisben.php');
}, 1000 );
})
function refrescaTurno() {
$.ajax({
url: "prueba1.php",
dataType:'json'
}).done(function(response) {
if(response.turno != turno_actual) {
turno_actual = response.turno;
desplegarAlerta();
}
window.setTimeout(refrescaTurno, 2000);
});
}
refrescaTurno();
Well, the idea is to update div
every time there is a change in db
, but I could make an alert using swal
and it works.
photo:
var turno_actual = 0;
function desplegarAlerta() {
swal({
title: "siguiente turno : " + turno_actual,
text: "Se envio correctamente",
icon: "success",
button: true
});
}
function refrescaTurno() {
$.ajax({
url: "prueba1.php",
dataType:'json'
}).done(function(response) {
if(response.turno != turno_actual) {
turno_actual = response.turno;
desplegarAlerta();
}
window.setTimeout(refrescaTurno, 2000);
});
}
refrescaTurno();
But when trying to do it with only the div
that is on the page,
with the code I left above it does not show me the number.
The code I am using to work for me at the moment is this:
$(document).ready(function() {
var refreshId = setInterval(function() {
$('#turno-sisben').load('./vistas/ajax/sisben.php');
$('#turno-familia').load('./vistas/ajax/familias_en_accion.php');
$('#turno-salud').load('./vistas/ajax/salud.php');
$('#turno-despacho').load('./vistas/ajax/despacho.php');
$('#turno-adulto').load('./vistas/ajax/adulto_mayor.php');
}, 1000 );
})
but overload when many requests are used at the same time since every second is updated