我已经实现了以下代码:
我有一个这样的 html 按钮:
HTML
<button style="background-color: #f39900;" onclick="downCont()">
Download all content
</button>
Run Code Online (Sandbox Code Playgroud)
downCont()单击时调用的函数是ajax POST这样的:
查询
var downCont = function() {
$.ajax({
method: "POST",
contentType: "application/x-www-form-urlencoded",
url: "<endpoint here>",
data: {
"tokenId": token,
"downloadId": "cz98567354",
"saveAs": "AllContents"
}
})
.done(function() {
alert("I have downloaded all contents!");
});
});
Run Code Online (Sandbox Code Playgroud)
现在,此POST请求的响应用于下载直接流式传输给用户的图像存档(content-type: application/octet-stream)。如何通过浏览器本身使用 触发下载档案jQuery?