function post(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
//調用方法 如
post('pages/statisticsJsp/excel.action', {html :prnhtml,cm1:'sdsddsd',cm2:'haha'});
post方式提交參數並下載文件:
正常情況下下載用windows.open(URL)
,若想用post傳參可以用如下方式,生成action為URL的表格,然后利用form傳參並跳轉,由於跳轉URL實際上是被下載的文件,所以瀏覽器會開始下載並保留原來頁面(不確定?)。
var temp = document.createElement("form");
temp.action = "catalogDetail.do?method=Download";
temp.method = "post";
temp.style.display = "none";
var PARAMS = {
"cata_id" : $("input[name='cata_id']").val(),
"where" : filter_condition.where,
"columns" : $("#gaojishaixuan_fenzu_column").val()
};
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
$(temp).remove();