Use of jQuery.form and jQuery.validate

Two submission methods of jquery.form

Method 1: ajaxForm

The ajaxForm method must first bind the form, which is generally defined in $(document).ready(function(){}), which allows the form to post to the target without refreshing the page, for example:

$(document).ready(function(){
   $('#updateForm').ajaxForm(function(){
        alert("ajaxForm提交完成");
   }); 
});

Method 2: ajaxSubmit

The ajaxSubmit method is to submit the form through the ajax method by the corresponding event, such as clicking a button to trigger the submission of the form, for example:

$('#btnTest').on('click',function(){
    $('#updateForm').ajaxSubmit(function(){
        alert("ajaxForm提交完成!");
    });
});

Three ways to submit jquery.validate + jquery.form

Method 1: Through the submintHandler option of jquery.validate, that is, when the form passes the validation, the callback function is executed, and the form is submitted through jquery.form in this callback function;


Method 2: Through the beforeSubmit of jquery.form, that is, the callback function is executed before submitting the form. If this function returns true, the form is submitted. If it returns false, the submission of the form is terminated. According to the valid() method of the jquery.validate plugin, you can Validate the form when submitting the form through jquery.form;


Method 3: Through the validate() method of jquery.validate, the advantage of this method is that the control of form validation is more free.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325945086&siteId=291194637