var openPostWindow =function (url, data1) {//url 为请求地址,data1为需要请求的数据
var tempForm = document.createElement("form");//创建form表单,以下数form表单的各种参数
tempForm.id = "tempForm1";
tempForm.method = "post";
tempForm.action = url;
var hideInput1 = document.createElement("input");//创建标签 <input></input> 标签 然后设定属性,最后追加为 form标签的子标签
hideInput1.type = "hidden";
hideInput1.name = "result";
hideInput1.value = data1;
var hideInput2 = document.createElement("input");
hideInput2.type = "hidden";
hideInput2.name = "CSRFToken";
hideInput2.value = JSON.parse(data1).CSRFToken;
var hideInput3 = document.createElement("input");
hideInput3.type = "hidden";
hideInput3.name = "l";
hideInput3.value = data1.length;
tempForm.appendChild(hideInput1);
tempForm.appendChild(hideInput2);
tempForm.appendChild(hideInput3);
if (document.all) {
tempForm.attachEvent("onsubmit", function () {
}); //IE
} else {
var subObj = tempForm.addEventListener("submit", function () {
}, false); //firefox
}
document.body.appendChild(tempForm);
if (document.all) {
tempForm.fireEvent("onsubmit");
} else {
tempForm.dispatchEvent(new Event("submit"));
}
tempForm.submit();//提交POST请求
document.body.removeChild(tempForm);//删除整个form标签
}
亲测可用!!!