how to submit multiple forms with single submit?

2019-01-25 01:44发布

问题:

I have multiple forms on the same page but I want to submit all forms together once instead of submitting one at a time. My approach is to clone all the data inside a another form and submit at once but its kind of overhead . So, is there a another approach to submit multiple form data once.

Thanks in advance for any help.

回答1:

This will submit all form elements via ajax when 'button' is clicked

$('button').click(function() {
    $('form').each(function() {
        $.post(this.action, $form.serialize());
    });
});

Note that this will not refresh the page, as they are all submitted via ajax...



回答2:

Hmmmm. This might sound drastic, but why not encapsulate all the INPUTs into just one FORM element? If not that, I think you'll have to rely on AJAX to do this for you.



回答3:

You could either do it the way that your doing it, or you can submit the forms via ajax requests. If there is no need for it to be asynchronous, I would probably do it the way you plan on doing it.