【发布时间】:2020-07-31 10:50:08
【问题描述】:
我正在尝试从 AJAX GET 请求下载包含 JSON 文件的 Zip 文件。
响应头格式:
Connection: keep-alive
content-disposition: attachment;filename=exportedFiles_ 1.6.0_20200731160652.zip
Content-Length: 4496
Content-Type: application/octet-stream
Date: Fri, 31 Jul 2020 10:36:52 GMT
网络选项卡中的数据预览:
AJAX调用及成功函数:
$.ajax({
type: "GET",
url: "/download/" ,
async: false,
success: function (data,status, xhr) {
var filename = xhr.getResponseHeader('content-disposition').split("filename=")[1];;
var blob = new Blob([data], {type: "octet/stream"})
saveAs(blob, filename);
}
});
它正在保存 Zip 文件,但是当我尝试打开 Zip 文件时,它显示“Windows 无法打开文件夹,压缩的 Zip 无效”。
【问题讨论】:
-
遇到类似问题,请问您解决了吗?
标签: javascript ajax rest download zip