Reputation: 633
What i am trying to do here is one click that sends out two posts. Here is my html
<form id="input" method="post" action="http:\\example.com\try">
<input type="text" name="info1" id="text1"/>
<input type="submit" id="submit"/>
</form>
<form id="input2" method="post" action="http:\\example.com\try">
<input type="text" name="info2" id="text2"/>
</form>
And the script
$("#submit").click(function() {
$("#text2").submit();
});
what I thought was after I click on the submit button for the first form, the submittion for the second form should also be triggered, I should received 2 posts on my server side ,example.com/try. But turns out the server only receives the second post, which is info2 and also according to the chrome console, only the second post was triggered. Any idea why? is this feasible if not at all? By the way, the server and the APP are in different domains.
Upvotes: 1
Views: 184
Reputation: 83356
$("#text2").submit();
is triggering a page postback before the original submit event can complete, and post your first form. Also, instead of calling submit()
on the submit button, I think it's more standard to call it on the actual form, which for you would be: $("#input2").submit();
If you want to post two forms like that, you'll have to fire off ajax requests for both, and handle their callbacks.
Upvotes: 1