Search code examples
jqueryajaxvalidationlive

jquery validation plugin inside ajax loaded content


I am using jquery validation plugin to validate an ajax submited form. the ajax call returns the html of the form if there was some error server side.

The problem is if this happens to ajax doens´t work anymore. I would need something like "live" jquery function that works with the jquery validation plugin.

here is my code:

$('#myform').validate({
            submitHandler: function(form) {
              formData = $(form).serialize();


              $.ajax({
                    type: "POST",
                    url: form.action,
                    data: formData ,
                    dataType: 'json',
                    success: function(response){
                        if(response.status == "success")
                            window.location.reload(true);
                        else
                           $('#myformdiv').html(response.html);

                    },
                    error: function(response){

                    }
                });

              return false;
            }
        });

Solution

  • you should consider reading this question and my answer to it