传统方式href带参数后边直接添加键值对即可,但是无法传token
解决办法,附代码:
var xhr = new XMLHttpRequest();
xhr.open("get", url, true); // get、post都可
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader("Authorization", updateToken("<%=basePath%>")); // token键值对
xhr.onload = function() {
if (this.status == 200) {
var blob = this.response;
var a = document.createElement("a")
var url = window.URL.createObjectURL(blob)
a.href = url
a.download = ".xls" // 文件名
}
a.click()
window.URL.revokeObjectURL(url)
} }
xhr.send();
代码亲测有效哦,这样就可以实现href携带token跳转连接了!