1. 程式人生 > >ajax請求文件流下載

ajax請求文件流下載

nsh move code auth type 文件流 domain dst oss

$.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請求文件流下載