上传disen修改版

This commit is contained in:
wang_chengh 2023-09-22 11:20:25 +08:00
parent 34dd311567
commit eee29c3750
1 changed files with 41 additions and 27 deletions

View File

@ -36,11 +36,11 @@
<body>
<div>
<form onsubmit="return post_ip(this);" class="blackfrom">
<form class="blackfrom">
<label>ip地址:</label>
<input name="ipaddr">
<button type="submit">添加</button>
<button type="button" id="del">删除</button>
<input name="ipaddr" id="ipInputID">
<button type="button" onclick="add_ip()">添加</button>
<button type="button" id="del" onclick="del_ip()">删除</button>
</form>
<table class="balckTable back" width="250" align="center" border="1" cellspacing="0">
<thead>
@ -52,7 +52,8 @@
</table>
</div>
<script>
window.onload = function () {
function loadData() {
fetch("/cgi-bin/fw.cgi").then(resp => resp.json()).then(data => {
blackTableBody.innerText = "";
data.forEach(rowData => {
@ -64,37 +65,50 @@
tr.append(td1);
blackTableBody.append(tr);
});
}
)
})
}
window.onload = function () {
loadData();
let del = document.getElementById("del");
del.addEventListener("click", (event) => {
fetch("/cgi-bin/send.cgi").then(resp => resp.json()).then(data => {
if (data.code == 1) {
alert("删除成功!");
}
})
}
)
}
function post_ip(form) {
let form_data = {
ip: form.ipaddr.value
function add_ip() {
let url = "/cgi-bin/send.cgi";
let data = {
"code": 0,
"ip": ipInputID.value.trim()
};
fetch("/cgi-bin/send.cgi", {
fetch(url, {
method: "post",
body: JSON.stringify(form_data),
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json;charset=utf-8"
}
}).then(resp => resp.json()).then(data => {
if (data.code == 0) {
alert("添加成功!");
}).then(resp => resp.json()).then(d => {
console.log(d);
loadData();
});
}
function del_ip() {
let url = "/cgi-bin/send.cgi";
let data = {
"code": 1,
"ip": ipInputID.value.trim()
};
fetch(url, {
method: "post",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json;charset=utf-8"
}
})
onload();
return false;
}).then(resp => resp.json()).then(d => {
console.log(d);
loadData();
});
}
</script>
</body>