无法提交生成的表单 [英] Can't submit generated form
问题描述
我想提交一个已经使用AJAX动态创建的表单(通过之前的表单提交),但是我无法让它成功运行。生成的表单具有显示的格式,并且正在成功创建
< div id =1class =container-元素>
< h3> HEADER< / h3>
< form id =formCELLname =form_1action =refresh.phpmethod =post>
< div class =panel-body>
< div class =col-xs-10 com> CONTENT GOES HERE< / div>
< div class =col-xs-2 btn>< button class =btn btn-primaryid =refreshtype =submit>刷新< / button> < / DIV>
< / div>
< / form>
< / div>
用于生成表单然后刷新内容的函数就在这里。现在,当单击刷新按钮时,不会输入 $('#formCELL')。submit(函数(事件)
函数。
$(document).ready(function(){
$('#formMAIN')。submit(function ){
// formCELL通过AJAX调用在这里生成.....
));
$('#formCELL') .submit(函数(事件){
//处理表单
alert(将要提交);
// AJAX调用去这里
event.preventDefault();
});
});
我猜这个问题与我的 $(document).ready
中的提交函数有关,我想要刷新的表单在这一点上还没有创建,但我不知道如何继续从这里。
尝试:
$(document).on('submit','#formCELL',function(eve nt){...});
我为你创建了一个jsFiddle:
< a href =https://jsfiddle.net/odsqhc6a/3/ =nofollow> JsFiddle
我根据您的需要修改jsFiddle 。现在首先生成由seconf提交函数处理的第二个表单
I want to submit a form that's been created dynamically (by a previous form submit) using AJAX, but I'm not able to get it to work successfully. The generated form has the format shown, and is being created successfully
<div id="1" class="container-element">
<h3>HEADER</h3>
<form id="formCELL" name="form_1" action="refresh.php" method="post">
<div class="panel-body">
<div class="col-xs-10 com">CONTENT GOES HERE</div>
<div class="col-xs-2 btn"><button class="btn btn-primary" id="refresh" type="submit">Refresh</button> </div>
</div>
</form>
</div>
The functions used to generate the form, and then refresh the content, is here. Right now, the $('#formCELL').submit(function(event)
function isn't being entered when the refresh button is clicked.
$(document).ready(function() {
$('#formMAIN').submit(function(event) {
//formCELL is generated here through AJAX call.....
});
$('#formCELL').submit(function(event) {
// process the form
alert("about to submit");
//AJAX call to go here
event.preventDefault();
});
});
I'm guessing that the problem has to do with me having my submit function within $(document).ready
, that the form I want to refresh hasn't been created at this point yet, but I'm not sure how to continue from here.
Try:
$(document).on('submit', '#formCELL', function(event) { ... });
I create a jsFiddle for you: JsFiddle
I modify the jsFiddle according your needs. Now first form generate second form that is handled by seconf submit function
这篇关于无法提交生成的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!