zoukankan      html  css  js  c++  java
  • 文件流下载

    dllalsdf(){
            //  获取时间戳
            let timestamp=new Date().getTime();
            // 获取XMLHttpRequest
            let xmlResquest = new XMLHttpRequest();
            //  发起请求
            xmlResquest.open("POST",'/pc/authority/exportAuthority', true);
            // 设置请求头类型
            xmlResquest.setRequestHeader("Content-type", "application/json");
            //  设置请求token
            xmlResquest.setRequestHeader(
              "Authorization",
              getToken()
            );
            xmlResquest.responseType = "blob";
            //  返回
            xmlResquest.onload = function(oEvent) {
            let content = xmlResquest.response;
            // 组装a标签
            let elink = document.createElement("a");
            // 设置下载文件名
            elink.download = timestamp + ".xlsx";
            elink.style.display = "none";
            let blob = new Blob([content]);
            elink.href = URL.createObjectURL(blob);
            document.body.appendChild(elink);
            elink.click();
            document.body.removeChild(elink);
            };
            xmlResquest.send(JSON.stringify({groupId: 270}));
          },
  • 相关阅读:
    iOS开源控件库收集
    Ruby中的几种除法
    Font
    PlaySound
    STL
    APIs
    cin and cout
    CreateWindow
    Introducing Direct2D
    VC 常用代码
  • 原文地址:https://www.cnblogs.com/HePandeFeng/p/12887459.html
Copyright © 2011-2022 走看看