我正在尝试转换现有的HTML表单并使其显示在JQuery对话框中。我不确定如何更改代码,以便在单击提交按钮后提交数据。我的代码如下:
旧表格:
<form method="post" name="callbackrequest" id="ccallbackrequest" action="action.php" onsubmit="return validateThis(this)">
<button type="submit" class="submit">Submit Request</button>
新表格:
buttons: {
"Submit": function() {
if ( bValid ) {
HERE GOES THE CODE!
$( this ).dialog( "close" );
}
然后是新表格:
<form class="center" method="post" name="callbackrequest" id="ccallbackrequest" action="??">
fields listed
no submit button
</form>
有关如何处理此问题的任何建议?
答案 0 :(得分:11)
让我们更进一步......这是一个用ajax提交的对话框表单!
<form id="modalform" style="display:none">
<input type="text" name="something">
<input type="text" name="somethingelse">
</form>
$("#modalform").dialog({ //Shows dialog
height: 250,
width: 450,
modal: true,
buttons: {
"Cancel": function() {
$( this ).dialog( "close" );
},
"Save": function() {
$.ajax({
url: "/url/to/submit", //
timeout: 30000,
type: "POST",
data: $('#modalform').serialize(),
dataType: 'json',
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("An error has occurred making the request: " + errorThrown)
},
success: function(data){
//Do stuff here on success such as modal info
$( this ).dialog( "close" );
}
}
});
答案 1 :(得分:5)
试试$('#ccallbackrequest').submit();
。 submit方法只提交选择器返回的任何一种形式。
答案 2 :(得分:3)
你只需要输入
$("#FORM_ID").submit()