开发者

trigger jquery validate() on button click

开发者 https://www.devze.com 2022-12-15 17:56 出处:网络
i have form and i am using jquery validate jquery.validate.pack.js its work fine when i press submit button, i just add following code

i have form and i am using jquery validate jquery.validate.pack.js

its work fine when i press submit button, i just add following code

            $(document).ready(function(){
        $("#contactform").validate();
            });

and class="validate" for text box

but i want to call php file with Ajax after validat开发者_Go百科e is complete.

like $.ajax({ type: "POST", url: "email_feedback.php", etc

how can i do this ?

Thanks


See the submitHandler callback option in http://docs.jquery.com/Plugins/Validation/validate#options

$("#contactform").validate({
   submitHandler: function(form) {
    //$(form).ajaxSubmit(); // for the default ajax submission behavior
     $.ajax({ type: "POST", url: "email_feedback.php"})//, etc... for your own
   }
})


This will submit the form to the URL that is in the action attribute of the form via AJAX though:

$("#contactform").validate({
   submitHandler: function(form) {
    $(form).ajaxSubmit();
   }
})

Here's an additional link for you as well: http://www.malsup.com/jquery/form/#api

Thanks, Orokusaki

0

精彩评论

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