esp32c3-usb_serial/main/wifi/www/wifi.html
2025-03-15 22:17:12 +08:00

48 lines
1.6 KiB
HTML

<!DOCTYPE html>
<meta charset='UTF-8'>
<table class="fixed" border="0">
<col width="1000px" /><col width="500px" />
<h3>wifi 密码配置</h3>
<div>
<label for="name">wifi名称</label>
<input type="text" id="wifi" name="car_name" placeholder="ssid">
<br>
<label for="type">密码</label>
<input type="text" id="code" name="car_type" placeholder="password">
<br>
<button id ="send_WIFI" type="button" onclick="send_wifi()">提交</button>
</div>
</table>
<script>
function setpath() {
var default_path = document.getElementById("newfile").files[0].name;
document.getElementById("filepath").value = default_path;
}
function send_wifi() {
var input_ssid = document.getElementById("wifi").value;
var input_code = document.getElementById("code").value;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/config", true);
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
console.log(xhttp.responseText);
} else if (xhttp.status == 0) {
alert("Server closed the connection abruptly!");
location.reload()
} else {
alert(xhttp.status + " Error!\n" + xhttp.responseText);
location.reload()
}
}
};
var data = {
"wifi_name":input_ssid,
"wifi_code":input_code
}
xhttp.send(JSON.stringify(data));
}
</script>