var formData = new FormData(layero.find('form')[0]);
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
$.modal.closeAll();
var blob = this.response;
var filename = "工程订单导入错误.xls";
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob,filename);
} else {
var a = document.createElement('a');
var url = URL.createObjectURL(blob);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
}
}
};
xhr.open("POST", table.options.importUrl);
xhr.send(formData);
导入exel后端校验完直接返回结果excel流前端自动下载
最新推荐文章于 2023-11-28 11:27:59 发布
本文介绍了一种使用XMLHttpRequest和FormData对象进行文件上传,并在成功后触发文件下载的方法。适用于需要从服务器获取文件并直接下载到客户端的场景,如导出错误报告等。
858

被折叠的 条评论
为什么被折叠?



