当前位置:网站首页>JS post download file
JS post download file
2022-06-29 10:46:00 【linsa_ pursuer】
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> download </title>
<script>
var xmlhttp = getXMLHttpRequest();
var record = "747140577079087276";
var url = "http://xxx.com/controller/download?docId=" + record;
xmlhttp.open("POST", url, true);
xmlhttp.responseType = 'blob';
xmlhttp.setRequestHeader("Content-Type","application/json");
xmlhttp.setRequestHeader("Authorization","bearer 6870332e-6741-461b-840f-6e49fcce3baf");
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log('111');
saveAs(xmlhttp.response, record + ".xlsx");
}
};
function getXMLHttpRequest() {
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHttp");
}
return xmlhttp;
}
function saveAs(data, name) {
const blob = new Blob([data]);
const aElement = document.createElement('a');
const blobUrl = window.URL.createObjectURL(blob);
aElement.href = blobUrl;
aElement.download = name;
aElement.click();
window.URL.revokeObjectURL(blobUrl);
}
</script>
</head>
<body>
</body>
</html>
边栏推荐
猜你喜欢
随机推荐
Analysis on the specific execution process of an insert statement in MySQL 8.0 (2)
FreeRTOS porting of official website based on keil5 auto configuring STM32F103 standard library
【C语言进阶】特殊自定义类型
The use and difference of watch listening and computed calculation attributes
在实践中学习Spark计算框架(01)
【C语言进阶】字符串和内存函数(二)
打印9*9乘法口诀表(C语言)
Buuctf-- connotative software
攻防世界-Re-insfsay
【动态规划】—— 线性DP
C语言库函数--strstr()
细粒度识别、分类、检索数据集整理
Learn spark computing framework in practice (00)
高薪程序员&面试题精讲系列117之怎么保证Redis缓存与数据库的数据一致性?
SQL Server 数据库的几种简单查询
The difference between & & and &
深入浅出总结Flink运行时架构
Is it safe to open a securities account? Is it reliable?
打印100~200之间的素数(C语言)
1-数据库了解








