$.ajax({
type: "Post",
timeout : 200000,
//文件较大的要设置的时间长一些
xhrFields: {
responseType: "arraybuffer",
//buffer文件必须要加xhr原生的支持
},
url: "http://152.136.174.209:8080/api/exportPdf",
data: JSON.stringify(sendData),
//post接口的参数
contentType: "application/json;charset=utf-8",
//表示传的是json
success: function (result) {
console.log(result);
let blob = new Blob([result], {
//因为是buffer 用blob大对象接收
type: "application/pdf",
//设置类型的Wie想要的类型,如:pdf,excel等
});
let link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = "单位自查表.pdf";
//名字
link.click();
window.URL.revokeObjectURL(link.href);
},
});
Ajax:下载文件
发布于 2021-08-11 1076 次阅读
Comments | NOTHING