function modifyx(data, url) {
// 发送POST请求
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(responseData => {
showmsg("修改成功");
})
.catch((error) => {
showmsg("修改失败");
});
}
document.getElementById('dynamic-form').addEventListener('submit', function (event) {
event.preventDefault(); // 阻止表单默认提交行为
// 获取表单数据
const formData = new FormData(this);
const url = this.action;
const data = {};
formData.forEach((value, key) => {
data[key] = value;
});
modifyx(data, url);
});
//=====================================
function submit(showlog = true) {
// 获取表单数据
// 获取表单数据
const form = document.getElementById('dynamic-form');
const formData = new FormData(form);
const url = form.action;
const data = {
"key": 'task',
};
formData.forEach((value, key) => {
data[key] = value;
});
modifyx(data, url, showlog);
}