📜  仅当提交有效时 javscript 才发送 ajax 请求 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:33.485000             🧑  作者: Mango

代码示例1
$( document ).ready( function(){setupForms();} );

function setupForms(){

    var ajaxOptions = { beforeSubmit:checkForm,
                        success:function(){
                               // the ajax was successful
                       }
                      };

    $( '.ajaxForm' ).ajaxForm( ajaxOptions );   
    $( '.ajaxForm' ).validate();
}

function checkForm(data,form){
    var valid = $(form).valid();
    return valid;
}