From 372cf830ae25b43be13dbed31d3685e79ed3c385 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 1 Jan 2023 18:32:23 +0100 Subject: [PATCH] Add timeout to javascript queries --- data/www/script.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/data/www/script.js b/data/www/script.js index f4d87b8..c89a141 100644 --- a/data/www/script.js +++ b/data/www/script.js @@ -1,13 +1,11 @@ function play() { console.log("Play..."); - var xhttp = new XMLHttpRequest(); - xhttp.open("GET", "play", true); - xhttp.send(); + fetch("/play", { signal: AbortSignal.timeout(7000) }); } function loadAvailableFiles() { console.log("Available files..."); - fetch("/available-files") + fetch("/available-files", { signal: AbortSignal.timeout(7000) }) .then(response => response.json()) .then(handleAvailableFiles); } @@ -16,7 +14,7 @@ function selectFile(name) { console.log("Select file"); const body = new FormData(); body.set("fileName", name); - fetch("/select-file", {method: "POST", body: body}) + fetch("/select-file", { method: "POST", body: body, signal: AbortSignal.timeout(7000) }) .then(response => response.json()) .then(handleAvailableFiles); }