JavaScript post request like a form submit向您展示了如何提交在JavaScript中通过POST创建的表单。下面是我修改过的代码。
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');
发布于 2008-10-07 15:23:31
添加
<form target="_blank" ...></form>
或
form.setAttribute("target", "_blank");
添加到表单的定义中。
发布于 2008-10-08 00:54:56
如果你想从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();
发布于 2012-09-25 04:55:07
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();
https://stackoverflow.com/questions/178964
复制相似问题