zoukankan      html  css  js  c++  java
  • 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)
                                }
                            }
                        })
  • 相关阅读:
    【排序】冒泡排序,C++实现
    【排序】选择排序,C++实现
    【排序】插入排序,C++实现
    【集成学习】 lightgbm原理
    leetcode1310
    leetcode1309
    leetcode1300
    leetcode1302
    leetcode1299
    leetcode1306
  • 原文地址:https://www.cnblogs.com/SunShineM/p/9084755.html
Copyright © 2011-2022 走看看