rogers
rogers

Reputation: 365

How to get the formatted POST data of a Django form?

I have a Django ModelForm but don't want the user to click on a reguar submit button. Instead, I made my own submit button and will post the form data using Ajax/jQuery. The data to post is a mix of the form data plus other information I gather on my UI. But... how do i get the formatted POST data the html form was supposed to submit? If I can get it like JSON or jQuery object, better!

Upvotes: 1

Views: 1197

Answers (1)

BalusC
BalusC

Reputation: 1108772

You can use jQuery.serialize() for this which you in turn can pass as 2nd argument of jQuery.post().

$('#formid').submit(function() {
    $.post('serverUrl', $(this).serialize(), callbackFunction);
    return false;
});

Alternatively, you can also use the jQuery Form plugin for this, which makes stuff easier.

Upvotes: 1

Related Questions