Files
P80-Webserver/static/config.js
2025-10-02 22:43:24 +03:00

36 lines
1.1 KiB
JavaScript

async function get_config() {
response = await fetch("/config?json", {method: "GET", headers: {"Accept": "application/json"}})
if (! response.ok){
throw Error("config data request error: " + await response.text())
}
return response.json()
}
async function render_config(){
params = await get_config()
for (par of Object.keys(params)) {
if (params.par == null) {
params.par = ""
}
}
const {address, port, profile} = params
document.getElementById("address").value = address
document.getElementById("port").value = port
document.getElementById("profile").value = profile
}
async function send_config() {
address_value = document.getElementById("address").value
port_value = document.getElementById("port").value
if (port_value == ""){
port_value = null
}
else{
port_value = parseInt(port_value)
}
response = await fetch("/config", {method: "POST", headers: {"Accept": "application/json", "Content-Type": "application/json"},
body: JSON.stringify({"address": address_value, "port": port_value, })})
document.location.reload()
}