开发者

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

开发者 https://www.devze.com 2023-01-06 08:07 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消