poi 導(dǎo)出 excel 解決 post 攜帶參數(shù)發(fā)送請求
一般情況下,我們通過ajax獲取數(shù)據(jù)都是采用get方式獲取,但如果ajax的請求url過長時,get方式由于瀏覽器對url長度不同會導(dǎo)致無法正常獲取數(shù)據(jù),尤其是IE。
這時候,我們需要通過post請求的方式獲取數(shù)據(jù),而如果我們需要通過post方式導(dǎo)出Excel表格,則需要通過表單提交的方式導(dǎo)出Excel。
function postExcelFile(params, url) { //params是post請求需要的參數(shù),url是請求url地址
var form = document.createElement("form");
form.style.display = 'none';
form.action = url;
form.method = "post";
document.body.appendChild(form);
for(var key in params){
var input = document.createElement("input");
input.type = "hidden";
input.name = key;
input.value = params[key];
form.appendChild(input);
}
form.submit();
form.remove();
}
//點擊導(dǎo)出按鈕導(dǎo)出excel表格
exportButton.onclick = function() {
var params = {};
postExcelFile(params, "http://www.XXX_excel");
}
————————————————
版權(quán)聲明:本文為CSDN博主「飛翔在藍天下的蜂鳥」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_33036599/article/details/80844430
浙公網(wǎng)安備 33010602011771號