I am having trouble submitting a dynamically created form. I have tried a lot of methods but the form is not getting submitted. Here are couple of methods I have tried.
In this code tosubmit
is actually a json string created using JSON.stringify
. I am also not getting any error when I debug this using Opera Dragonfly
. I can see the form properly added to the DOM.
Method 1
var frmstr = '<form id="tbl_tmpfrm" method="post" action="/test.php">';
frmstr +='<input type="hidden" name="submit" value="true"/><input type="hidden" name="data" value=""/></form>';
$('body').append(frmstr);
$('#tbl_tmpfrm').find('input[name="data"]').val(tosubmit);
$('#tbl_tmpfrm').submit();
Method 2
var frmstr = '<form id="tbl_tmpfrm" method="post" action="/test.php">';
frmstr +='<input type="hidden" name="submit" value="true"/><input type="hidden" name="data" value="'+tosubmit+'"/></form>';
$('body').append(frmstr).submit();
I am able to successfully submit the tosubmit
and validate at the server side when i use ajax
. But I want a normal commit. What am I doing wrong?
Please help. Thanks.
See Question&Answers more detail:os