结合jquery validate和ajaxForm插件

时间:2009-11-20 10:09:42

标签: jquery plugins validation ajaxform

我有验证和ajaxform单独工作,但是当我尝试组合表单时不能正常工作。我对JQuery并不熟悉,所以认为语法在某处是错误的。谁能发现我做错了什么?

表单在验证之前需要两次尝试,然后表单发送但不给出任何响应。

//在DOM准备好时准备表单 $(document).ready(function(){ var options = { target:'#output1',//要用服务器响应更新的目标元素 beforeSubmit:showRequest,//预提交回调 success:showResponse // post-submit回调 };

//使用'ajaxForm'绑定表单 $( '#形式WebCheck可')给ajaxForm(选项)。 });

function showRequest(){ $( “#形式WebCheck可”)验证(); jQuery.validator.messages.required = jQuery.validator.messages.email =“”; jQuery.validator.messages.required = jQuery.validator.messages.telephone =“”; jQuery.validator.messages.required = jQuery.validator.messages.name =“”; }

function showResponse(){ 警报('感谢您的评论!'); }

1 个答案:

答案 0 :(得分:1)

$(document).ready(function() { 
    var options = { 
        //target:        '#response',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
    }; 

    // bind form using 'ajaxForm' 
    $('form#webcheck').ajaxForm(options); 
}); 

function showRequest(){ 
    jQuery.validator.messages.required = jQuery.validator.messages.email = "";
    jQuery.validator.messages.required = jQuery.validator.messages.telephone = "";
    jQuery.validator.messages.required = jQuery.validator.messages.name = "";
    $("form#webcheck").validate().form();

}

function showResponse(){ 
    alert('Thanks for your comment!'); 
}