预填并提交隐藏表单

3
我有一个表单,这里是提交按钮的处理程序:
$( '#submit_btn' ).click( function( data ){ 
    theForm = document.getElementById( 'realForm' );
    theForm.meetingName.value = document.getElementById( 'meeting_name' ).value;
    theForm.meetingId.value = '';
    theForm.description.value = document.getElementById( 'mtg_description' ).value;
    theForm.startTime.value = startDate + ' ' + startTime;
    theForm.endTime.value = endDate + ' ' + endTime;
    theForm.loginName.value = participants;
    theForm.role.value = roles;
    theForm.docRights.value = docRights;
    theForm.submit();
});

这个处理程序基本上预处理一些数据并将其发送到一个隐藏表单中,如下所示:
<form id="realForm" style="visibility:hidden" action="/app/meeting/create" method="post">
    <input name="loginName" type="text">
    <input name="meetingName" type="text">
    <input name="meetingId" type="text">
    <input name="startTime" type="text">
    <input name="endTime" type="text">
    <input name="description" type="text">
    <input name="roles" type="text">
    <input name="docRights" type="text">
</form>

问题是请求没有命中隐藏表单中定义的端点。我在这里做错了什么?
我已经更改为将输入类型更改为隐藏,而不是表单。提交处理程序肯定会执行,并且使用FireBug,我在NET选项卡下看不到请求发送出去。
我正在使用这个虚拟数据来尝试触发请求,但它仍然没有起作用:
theForm.meetingName.value       = "MY MTG";
                        theForm.meetingId.value         = '';
                        theForm.description.value       = "DESC";
                        theForm.startTime.value         = "2013-05-25 00:00:00";
                        theForm.endTime.value           = "2013-05-25 02:00:00";
                        theForm.loginName.value         = "foo@frr.com";
                        theForm.role.value              = "M,M";
                        theForm.docRights.value         = "CRUT,CRUT";

你检查过提交是否发生了吗?还是这是问题所在?使用Firebug并观察NET选项卡(或类似工具)。 - matthewpavkov
我没有答案,但是我有几个建议。你尝试过去掉 visibility:hidden 看看是否能工作吗?另外,也许可以尝试使用 'display:none' 而不是 'visibility:hidden'。 - Adam Plocher
2
为什么不提供带有隐藏字段的表单,而不是完全隐藏的表单? - Fals
4个回答

3
我会尝试这个:

我会尝试这个:

document.forms.realForm.submit()

2

两个技巧:

  1. use this for fetching variable from input.

    $("#NAME_OF_YOUR_INPUT_ID").val(); 
    
  2. use hidden input instead and identify each one with ID.

    <input id="docRights" type="hidden">
    

2
问题在于我的第一个表单有一个type="submit"的按钮...所以即使我不想提交表单,它也会提交。
为了防止这种情况发生,我不得不将其类型更改为"button"。
感谢所有及时的回复。

1
你的输入名称是roles而不是role
将你的JS代码改为以下内容:
theForm.roles.value = roles;

请查看 JS Fiddle:http://jsfiddle.net/jav6s/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接