問題描述使用XMLHttpRequest導出excel,但responseType有可能是blob,或者是json相關代碼 var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = "blob"; // 返回類型blob blob 存儲著大量的二進制數據
xhr.onload = function () { console.log(xhr) if (this.status === 200) { var blob = this.response; var reader = new FileReader();
reader.readAsDataURL(blob); // 轉換為base64,可以直接放入a標簽href
reader.onload = function (e) { var a = document.createElement("a"); // 轉換完成,創建一個a標簽用于下載
a.download = name + ".xls";
a.href = e.target.result;
$("body").append(a); // 修復firefox中無法觸發click
a.click();
$(a).remove();
};
}
}
xhr.send(); // 發送ajax請求
使用XMLHttpRequest導出excel
PIPIONE
2018-08-02 17:06:22