39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
$(document).ready(function () {
|
|
const idPartida = $("body").data("id-partida");
|
|
|
|
comprobarEstadoPartida(idPartida);
|
|
|
|
const intervalo = setInterval(function () {
|
|
comprobarEstadoPartida(idPartida, intervalo);
|
|
}, 3000);
|
|
});
|
|
|
|
function comprobarEstadoPartida(idPartida, intervalo = null) {
|
|
$.ajax({
|
|
url: "controladores/ControladorResultados.php",
|
|
type: "POST",
|
|
dataType: "json",
|
|
data: {
|
|
orden: "comprobarEstado",
|
|
idPartida: idPartida
|
|
},
|
|
success: function (respuesta) {
|
|
if (respuesta.error) {
|
|
console.error("Error:", respuesta.error);
|
|
return;
|
|
}
|
|
|
|
if (respuesta.terminada) {
|
|
if (intervalo !== null) clearInterval(intervalo);
|
|
|
|
$("#pantalla-espera").fadeOut(400, function() {
|
|
location.reload();
|
|
});
|
|
}
|
|
},
|
|
error: function () {
|
|
console.log("Error de comunicación con el controlador.");
|
|
}
|
|
});
|
|
}
|