JavaScript提交请求(如表单提交)向您展示了如何提交通过POST在JavaScript中创建的表单。下面是我修改的代码。
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();
我想做的是在新窗口中打开结果。我目前正在使用类似的方法在新窗口中打开页面:
onclick = window.open(test.html, '', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');
加
<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();
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();
我知道这个基本方法:
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>
作品!
流窗最简单的工作解决方案(在Chrome上测试):
<form action='...' method=post target="result" onsubmit="window.open('','result','width=800,height=400');">
<input name="..">
....
</form>
本文地址:http://javascript.askforanswer.com/tijiaopostbiaodanhoudakaiyigexianshijieguodexinchuangkou.html
文章标签:html , javascript , post
版权声明:本文为原创文章,版权归 javascript 所有,欢迎分享本文,转载请保留出处!
文章标签:html , javascript , post
版权声明:本文为原创文章,版权归 javascript 所有,欢迎分享本文,转载请保留出处!
评论已关闭!