码迷,mamicode.com
首页 > Web开发 > 详细

ajax请求文件流下载

时间:2018-05-24 19:58:06      阅读:867      评论:0      收藏:0      [点我收藏+]

标签:token   string   save   child   下载   explorer   doc   nbsp   tee   

$.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请求文件流下载

标签:token   string   save   child   下载   explorer   doc   nbsp   tee   

原文地址:https://www.cnblogs.com/SunShineM/p/9084755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!