原生ajax獲取數據流並下載

//獲取數據流 start

var oReq = new XMLHttpRequest();

oReq.open("post", url,true);

oReq.responseType = "arraybuffer";

oReq.onload = function(oEvent) {

console.log(oEvent)

var uint8A = new Uint8Array(oReq.response);

DEFAULT_URL = uint8A;

success(uint8A);

};

oReq.send(para);

 

var success=function(){

var export_blob = new Blob([data]);

var link = window.URL.createObjectURL(export_blob);

var a = document.createElement('a');

 a.href = link;

 a.download = new Date().getTime()+'.pdf';

 a.click();

window.URL.revokeObjectURL(link);

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章