diff --git a/script.js b/script.js index 31ee9ea..7324cc4 100644 --- a/script.js +++ b/script.js @@ -23,9 +23,9 @@ // make fetch function that calls cgi script with attributes (device id, api key, delay) const unlockDoor = (e, dID, aK, d) => { fetch(`${unlockUrl}?deviceID=${dID}&apiKey=${aK}&delay=${d}`) -// fetch(unlockUrl) - .then(response => response.text()) - .then(data => messageContainer.innerHTML = data); + .then(response => response.json()) + .then(data => messageContainer.innerHTML = data.message) + .catch(error => messageContainer.innerHTML = `Error: ${error}`) } const setSettings = () => { @@ -75,9 +75,7 @@ unlockButton.addEventListener("click", (e) => unlockDoor(e, deviceID, apiKey, 0)); - delayUnlockButton.addEventListener("click", function () { - messageContainer.innerHTML = "Delay Unlock"; - }); + delayUnlockButton.addEventListener("click", (e) => unlockDoor(e, deviceID, apiKey, delay)); document.body.onload = setSettings; let date = new Date();