[英]Submit the form returned by ajax
I want to submit the form returned by ajax but it's not submitting the form. 我想提交由ajax返回的表单,但不提交表单。
Here is the code I tried 这是我尝试的代码
This file is called 3.php 该文件称为3.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function(){
$("#submitform").on("click", function(){
$.post("4.php").done(function(data){
//$($.parseHTML(data)).find("#paypalsubmit").submit();
$($.parseHTML(data)).find("input[type='submit']").submit();
});
});
});
</script>
<div id="submitform">click</div>
4.php file 4.php文件
<form id="paypalsubmit" method="post" action="stackoverflow.com">
<input type="text" value="hello stack" name="inputt">
<input type="submit" name="submit" value="submit">
</form>
update used click function and it worked 更新使用的点击功能,它的工作原理
Tried another method still it doesn't work 尝试了另一种方法仍然无效
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function(){
$("#submitform").on("click", function(){
alert("hello");
$.post("4.php").done(function(data){
$("#formplace").html(data).find("#paypalsubmit").submit();
setTimeout(function(){
alert("submitting the form");
//$("#formplace").find("#paypalsubmit").submit();},
//$("#paypalsubmit").submit();},
$("#formplace").find("input[type='submit']").click();},
2000);
});
});
});
</script>
<div id="submitform">click</div>
<div id="formplace"> </div>
Thanks 谢谢
Instead use a virtual div to hold the form and then submit the form instead: 而是使用虚拟div来保存表单,然后提交表单 :
$.post("4.php").done(function(data){
var $div = $('<div>',{ html : data });
$div.find("form")[0].submit();
});
Not sure if form can be submitted as above i suggested. 我不确定是否可以如上所述提交表格。 But another way is to put the form in the page and then submit it: 但是另一种方法是将表单放在页面中,然后提交:
$.post("4.php").done(function(data){
$('body').append(data);
$("#paypalsubmit")[0].submit();
});
Replace below line 替换下面的行
$($.parseHTML(data)).find("input[type='submit']").submit();
To 至
$("#paypalsubmit").submit();
You should change out your on click for 您应该将点击更改为
$("#submitform").on("click", "#submitform", function() {
This will allow jQuery to see the newly created submit button. 这将允许jQuery查看新创建的Submit按钮。
I thinks ,you can't submit without action ("click") for new appended one ! 我认为,您不能在没有任何操作(“点击”)的情况下提交新添加的附件! For me ,used trigger is working .Find type submit instead of form id 对我来说,使用的触发器正在工作。查找类型而不是表单ID的提交
$(function(){
$("#submitform").on("click", function(){
alert("hello");
$.post("4.php").done(function(data){
$("#formplace").html(data).find(":submit").trigger("click");
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.