ajax请求文件流下载
Posted 微笑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ajax请求文件流下载相关的知识,希望对你有一定的参考价值。
$.ajax({
// url:BASEURL+‘/bill/download/invoice‘,
url:‘http://loan-test.yinshuitong.com/backorg/bill/download/invoice‘,
type:‘get‘,
data:{
invoiceIdStr:invoiceShell.id
},
crossDomain: true == !(document.all),
beforeSend: function(request) {
request.setRequestHeader("Authorization", tokenString);
},
responseType: ‘blob‘,
success:function(result){
const excelBlob = result.data
if (‘msSaveOrOpenBlob‘ in navigator) {
// Microsoft Edge and Microsoft Internet Explorer 10-11
window.navigator.msSaveOrOpenBlob(excelBlob, ‘invoice.pdf‘)
} else{
const elink = document.createElement(‘a‘) // 创建a标签
elink.download = ‘invoice.pdf‘
elink.style.display = ‘none‘
const blob = new Blob([excelBlob])
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
document.body.removeChild(elink)
}
}
})
以上是关于ajax请求文件流下载的主要内容,如果未能解决你的问题,请参考以下文章