change read sensors, trigger via web possible, modify js to fetch with HTTP_POST

This commit is contained in:
2021-07-22 21:08:23 +02:00
parent 3145949020
commit 770c2436fd
4 changed files with 68 additions and 39 deletions
+8 -2
View File
@@ -35,7 +35,7 @@ function rangeToOutput(range, output) {
document.getElementById(range).oninput = function () {
document.getElementById(output).innerHTML = this.value;
// add to pending range changes
rangeValues[range] = val;
rangeValues[this.id] = this.value;
}
}
@@ -75,7 +75,13 @@ document.addEventListener('DOMContentLoaded', () => {
// use data- attributes for action
document.querySelectorAll('.control').forEach((button) => {
button.onclick = () => {
fetch(`/action=${button.dataset.action}`)
fetch(`/action`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `control=${button.dataset.action}`
})
.then(response => console.log(response))
.catch(error => console.log('Error:', error));
}