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 mand to send it?
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 mand to send it?
Share Improve this question edited Jul 29, 2009 at 20:47 Matthew Groves 26.2k10 gold badges73 silver badges125 bronze badges asked Jul 29, 2009 at 19:44 Tony BorfTony Borf 4,6709 gold badges45 silver badges52 bronze badges3 Answers
Reset to default 10use the .serialize method.
var postData = $('#formId').serialize();
$.post(url, postData);
$("form").submit(function(e) {
e.preventDefault();
$.post("/url", $(this).serialize(), callbackFunction);
});
jquery form plugin is what you need.