add error catching to unlockDoor method, add event handler to delay open button
parent
06bef4ad75
commit
42952d70c4
10
script.js
10
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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue