0

I am using jQuery form plugin and it is working great. Now I am loading a form using ajax. On success callback I have code something like this

success: function(data) {
  $('#container').prepend(data);
  ajaxify_form();
}

var ajaxify_form = function() {
    $('.new_form').ajaxForm(options);
};

I need to do all that because I could not make jquery form work with 'live'.

Am I doing something wrong. Is there a better way to bind a form which was loaded through ajax so that I do not need to explicitly bind in every success callback.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nick Vanderbilt
  • 36,724
  • 29
  • 83
  • 106

1 Answers1

0

Somewhat similar to my answer here: jquery live event for added dom elements.

Use the livequery() plugin and do it once. It will trigger for both existing and new forms added to the DOM.

$('.ajax_form').livequery(function() {
  //use $(this) to apply form plugin   
});
Community
  • 1
  • 1
Gregg
  • 34,973
  • 19
  • 109
  • 214