Files
LampControler/data/data_backup/config1.html
2025-07-09 17:29:39 +08:00

50 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>ESP32 WiFi Setup</title>
<meta charset="UTF-8">
<script>
async function saveWiFiSettings() {
const ssid = document.getElementById("ssid").value;
const password = document.getElementById("password").value;
try {
const response = await fetch("/saveWiFi", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "ssid=" + encodeURIComponent(ssid) + "&password=" + encodeURIComponent(password)
});
if (response.ok) {
// 解析JSON响应
const result = await response.json();
alert(result.message || "WiFi 设置保存成功!");
} else {
// 尝试解析错误消息
try {
const errorResult = await response.json();
alert(errorResult.message || "保存失败,请重试。");
} catch (e) {
alert("保存失败,请重试。");
}
}
} catch (error) {
console.error("Error:", error);
alert("ok");
}
}
</script>
</head>
<body>
<h1>WiFi 设置</h1>
<form onsubmit="event.preventDefault(); saveWiFiSettings();">
<label for="ssid">SSID:</label><br/>
<input type="text" id="ssid" name="ssid"><br/><br/>
<label for="password">密码:</label><br/>
<input type="password" id="password" name="password"><br/><br/>
<input type="submit" value="保存">
</form>
</body>
</html>