jQuery Form plugin - how to make ajaxForm() "live"?

asfsadf picture asfsadf · Sep 26, 2010 · Viewed 9.1k times · Source

So I'm turning an "edit" form into an ajaxForm with the following:

$('#reviewForm').ajaxForm({
    success: function (response) {
        $('#bookReview').html(response);
    }
});

This returns the same form, that can be edited again, if necessary. The second form submission, however, no longer has the ajaxForm() attached to it, which makes sense.

How do I make sure this form is always an ajaxForm, no matter how many submissions have taken place, similar to how the live() function works?

Answer

Slotos picture Slotos · Oct 11, 2010
$('#myFormId').live('submit', function() {
    // submit the form
    $(this).ajaxSubmit();
    // return false to prevent normal browser submit and page navigation
    return false;
});

Sligtly modified example for ajaxSubmit from http://jquery.malsup.com/form/#api.