jQuery(document).ready(function($) {
var upadates = document.querySelector("#tab_export_form");
if (upadates) {
upadates.innerHTML ='<form id="uploadForm" method="post" target="targetifr" enctype="multipart/form-data"> <p >基本信息: <input type="file" class="files1" name="file1"/></ p> <p >检查准备工作信息: <input type="file" class="files2" name="file2"/></ p> <p >地面巡视检查: <input type="file" class="files3" name="file3"/></ p> <p >建设效果检查: <input type="file" class="files4" name="file4"/></ p> <p >检查结论: <input type="file" class="files5" name="file5"/></ p> <input type="button" id="btnss" value="上传" /> </form>';
}
function download(blobUrl) {
const a = document.createElement("a");
a.style.display = "none";
a.download = "download.xlsx";
a.href = blobUrl;
a.click();
document.body.removeChild(a);
}
$("#btnss").click(function() {
var formData = new FormData($("#uploadForm")[0]);
console.log(formData);
alert("文件正在下载,请稍等");
fetch("http://zbqy.updis.haomo-tech.com/file/filesUpload", {
method: "POST",
body: formData,
async: false
}).then(function(response) {
return response.blob();
}).then(function(myBlob) {
const blobUrl = window.URL.createObjectURL(myBlob);
download(blobUrl);
}).catch(function(error) {
console.log(error);
alert("网络连接异常,请重试");
})
});
});
网友评论