js接收文件流并下载
js接收文件流并下载
标签(空格分隔): js
在此输入正文
<script type="text/javascript">
function download(filename) {
var oReq = new XMLHttpRequest();
oReq.open("GET", "<你的返回流的Action路径>", true);
oReq.responseType = "blob";
oReq.onload = function (oEvent) {
var content = oReq.response;
var elink = document.createElement('a');
elink.download = filename;
elink.style.display = 'none';
var blob = new Blob([content]);
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
};
oReq.send();
}
</script>