save config prototype

This commit is contained in:
Siwat Sirichai 2024-01-01 20:56:37 +07:00
parent cd271efddd
commit f1db2c0487
5 changed files with 638 additions and 409 deletions

View file

@ -1,5 +1,5 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form enctype="multipart/form-data" id="config_form" onsubmit="send_config()" action="/save_config">
<form enctype="multipart/form-data" id="config_form" onsubmit="send_config(event)">
<h1>ESPMega PRO</h1>
<h3>Device Configurations</h3>
<p class="config_title">IP Address</p>
@ -34,10 +34,47 @@
<button type="button" class="conf" onclick="window.location.href='/'">Back</button><br /><br />
<b>SIWAT SYSTEM 2023</b>
</form>
<style>
<script>
function send_config() {
event.preventDefault();
// Get the form data
var formData = {
ip_address: document.getElementById("ip_address").value,
netmask: document.getElementById("netmask").value,
gateway: document.getElementById("gateway").value,
dns: document.getElementById("dns").value,
hostname: document.getElementById("hostname").value,
bms_ip: document.getElementById("bms_ip").value,
bms_port: document.getElementById("bms_port").value,
bms_useauth: document.getElementById("bms_useauth").checked,
bms_username: document.getElementById("bms_username").value,
bms_password: document.getElementById("bms_password").value,
bms_endpoint: document.getElementById("bms_endpoint").value,
web_username: document.getElementById("web_username").value,
web_password: document.getElementById("web_password").value
};
// Send the POST request
fetch("/save_config", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(formData)
})
.then(response => response.json())
.then(data => {
// Handle the response data
console.log(data);
})
.catch(error => {
// Handle any errors
console.error(error);
});
}
</script>
<style>
p.config_title {
font-size: 12;
font-weight: bold;