dede / static /script.js
asgsfhdsfhdfg's picture
Upload 2 files
fce6658 verified
raw
history blame contribute delete
632 Bytes
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault(); // 阻止表单默认提交行为
const formData = new FormData(this);
fetch('/request', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.error) {
alert(`错误: ${data.error}`);
} else {
document.getElementById('resultImg').src = data.img_path; // 更新图片路径
}
})
.catch(error => {
console.error('提交表单时出错:', error);
});
});