先请求文件
var xhr = new XMLHttpRequest();
xhr.open('GET', `http://localhost:8080/static/直营店运营平台使用说明书.pdf`);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.responseType = "blob";
监听进度
- 第一个方法监听
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
}
}, false)
xhr.onprogress = function (event)
if (event.lengthComputable) {
var percentComplete = event.loaded / event.total * 100
} else {
}
};
xhr.onload = function (oEvent) {
if (xhr.readyState === 4 && xhr.status === 200) {
var blob = new Blob([xhr.response], {type: 'binary'});
var csvUrl = URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = csvUrl;
link.download = 'abababababba.xlsx';
link.click();
}
}
xhr.send();
}