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, bett开发者_高级运维er!
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.
精彩评论