// $ajax 的xhrFields: { responseType: "blob" },设置失败所以使用了xhr
let param = 'templateId=' + oid.toString() +"&"+'templateName='+templateName.toString()// 参数处理
var url = '/imeweb/drawing/exportDrawingInfoExcel'
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true); // 也可以使用POST方式,根据接口
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xhr.responseType = "blob"; // 返回类型blob
xhr.onload = function () {
// 请求完成 返回200
if (this.status === 200) {
let content = this.response;
let a = document.createElement('a');
a.download = '模板详情.xlsx';
let blob = new Blob([content])
a.href = URL.createObjectURL(blob);
$("body").append(a);
a.click();
$(a).remove();
}
};
xhr.send(param) // 发送ajax请求
使用xhr post请求后端返回并下载excel
最新推荐文章于 2023-11-06 14:11:41 发布
关键词由CSDN通过智能技术生成