function downloadFile(id) { var xhr = new XMLHttpRequest(); xhr.open('POST', 'https://localhost/api/app/isp-detection/' + id + '/download'); xhr.responseType = 'blob'; xhr.setRequestHeader('Content-Type', 'application/octet-stream'); xhr.onload = function () { if (xhr.status === 200) { var a = document.createElement('a'); var url = window.URL.createObjectURL(xhr.response); console.log(url); a.href = url; a.download = id + '.xlsx'; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); } }; xhr.send(); }
标签:stream,application,url,javascript,octet,xhr,id From: https://www.cnblogs.com/xinzheng/p/18011156