eriktobben's avatar

Combine multiple forms and send everything in one request

Hi,

I have multiple forms on my page, and when the user submits I want to combine all forms into one "master form" / request that gets submitted to the server. Is that possible?

I have found that I can get all input with this code:

$('form').serialize();

But how do I send the serialized data as a POST request to the server?

Is there a better way of doing this?

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

Just send it via ajax.

$.ajax({
    url: '/the/url/to/post/to',
    dataType: 'json',
    type: 'post', // send as POST
    data: $('form').serialize(),
    success: function (data) {
        // do something with returned data, or not
    },
});

http://api.jquery.com/jquery.ajax/

1 like

Please or to participate in this conversation.