After submitting a POST form open a new window showing the result

JavaScript post request like a form submit shows you how to submit a form that you create via POST in JavaScript. Below is my modified code.

var form = document.createElement("form");


form.setAttribute("method", "post");
form.setAttribute("action", "test.jsp");


var hiddenField = document.createElement("input");


hiddenField.setAttribute("name", "id");
hiddenField.setAttribute("value", "bob");
form.appendChild(hiddenField);
document.body.appendChild(form); // Not entirely sure if this is necessary
form.submit();

What I would like to do is open the results in a new window. I am currently using something like this to open a page in a new window:

onclick = window.open(test.html, '', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');
292075 次浏览

<form target="_blank" ...></form>

或者

form.setAttribute("target", "_blank");

符合你表格的定义。

如果你想在 Javascript 中创建和提交你的表单,并且你想创建具有自定义特性的弹出窗口,我建议这个解决方案(我在我添加的行上面添加了注释) :

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "test.jsp");


// setting form target to a window named 'formresult'
form.setAttribute("target", "formresult");


var hiddenField = document.createElement("input");
hiddenField.setAttribute("name", "id");
hiddenField.setAttribute("value", "bob");
form.appendChild(hiddenField);
document.body.appendChild(form);


// creating the 'formresult' window with custom features prior to submitting the form
window.open('test.html', 'formresult', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');


form.submit();

我知道这个基本方法:

1)

<input type=”image” src=”submit.png”> (in any place)

2)

<form name=”print”>
<input type=”hidden” name=”a” value=”<?= $a ?>”>
<input type=”hidden” name=”b” value=”<?= $b ?>”>
<input type=”hidden” name=”c” value=”<?= $c ?>”>
</form>

3)

<script>
$(‘#submit’).click(function(){
open(”,”results”);
with(document.print)
{
method = “POST”;
action = “results.php”;
target = “results”;
submit();
}
});
</script>

管用!

var urlAction = 'whatever.php';
var data = {param1:'value1'};


var $form = $('<form target="_blank" method="POST" action="' + urlAction + '">');
$.each(data, function(k,v){
$form.append('<input type="hidden" name="' + k + '" value="' + v + '">');
});
$form.submit();

流程窗口最简单的工作解决方案(在 Chrome 上测试过) :

<form action='...' method=post target="result" onsubmit="window.open('','result','width=800,height=400');">
<input name="..">
....
</form>