Tony Borf
Tony Borf

Reputation: 4660

Jquery .post and form data

I am using .post to post my data to my controller. I would like to pass all the data that I have in a form. Is there an easy way to take all the form data and add it to the .post command to send it?

Upvotes: 4

Views: 824

Answers (3)

serg
serg

Reputation: 111265

jquery form plugin is what you need.

Upvotes: 0

John Sheehan
John Sheehan

Reputation: 78104

$("form").submit(function(e) {
    e.preventDefault();
    $.post("/url", $(this).serialize(), callbackFunction);
});

Upvotes: 3

redsquare
redsquare

Reputation: 78667

use the .serialize method.

var postData = $('#formId').serialize();
$.post(url,  postData);

Upvotes: 10

Related Questions