diff --git a/js/resultados.js b/js/resultados.js new file mode 100644 index 0000000..4ecd202 --- /dev/null +++ b/js/resultados.js @@ -0,0 +1,38 @@ +$(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."); + } + }); +}