• XHR post请求下载文件


                var filename = 'test.xlsx';
                var xhr = new XMLHttpRequest();
                xhr.open('POST', downloadExcel, true);
                xhr.setRequestHeader("Content-Type", "application/json");
                xhr.responseType = 'blob';
                xhr.onload = function(res) {
                    if (this.status === 200) {
                        var type = xhr.getResponseHeader('Content-Type');
                        var blob = new Blob([this.response], {type: type});
                        if (typeof window.navigator.msSaveBlob !== 'undefined') {
                            /*
                             * For IE
                             * >=IE10
                             */
                            window.navigator.msSaveBlob(blob, filename);
                        } else {
                            /*
                             * For Non-IE (chrome, firefox)
                             */
                            var URL = window.URL || window.webkitURL;
                            var objectUrl = URL.createObjectURL(blob);
                            if (filename) {
                                var a = document.createElement('a');
                                if (typeof a.download === 'undefined') {
                                    window.location = objectUrl;
                                } else {
                                    a.href = objectUrl;
                                    a.download = filename;
                                    document.body.appendChild(a);
                                    a.click();
                                    a.remove();
                                }
                            } else {
                                window.location = objectUrl;
                            }
                        }
                    }
                }
                xhr.send(JSON.stringify(list));
    

      

  • 相关阅读:
    51单片机学习1
    M41T11-RTC(实时时钟)
    ATmega8仿真——外部中断的学习
    C# 调用动态代码
    C# Attribute的用法
    DataTable相关
    addin1
    多线程信号源_红绿灯
    EF CodeFirst简单实例
    WCF配置Tcp协议
  • 原文地址:https://www.cnblogs.com/jiehanshi/p/12627112.html
Copyright © 2020-2023  润新知