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
  • 34,719
  • 24
  • 185
  • 251
Nick Vanderbilt
  • 34,224
  • 27
  • 82
  • 104

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
  • 33,473
  • 15
  • 101
  • 201