change read sensors, trigger via web possible, modify js to fetch with HTTP_POST
This commit is contained in:
+8
-2
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user