下载函数

function downFile({
var url= “”;
var request = new XMLHttpRequest();
request.open(“post”,url);
request.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded”)
request.responseType = ‘blob’
request.onload = function(){
var name = request.getResponseHeader(“Content-disposition”);
var filename = name.substring(20,name.length);
// var filename = name.substring(name.lastIndexOf('.')+1,name.length;
var blob = new Blob([request.response], {type: ‘text/xls’}); var csvUrl = URL.createObjectURL(blob); var link = document.createElement(‘a’); link.href = csvUrl; link.download = filename;
//
link.download = '材料.'+filename;
link.click(); } request.send(); })

 

posted @ 2021-11-16 09:05  54墨玉  阅读(32)  评论(0编辑  收藏  举报