结合 jquery validate 和 ajaxForm 插件

发布于 2024-08-12 15:44:24 字数 695 浏览 4 评论 0原文

我的验证和 ajaxform 单独工作都很好,但是当我尝试组合表单时,表单无法正常工作。我对 JQuery 不太熟悉,所以认为语法在某个地方是错误的。谁能发现我做错了什么吗?

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

// 当 DOM 准备好时准备表单 $(文档).ready(函数() { 变量选项= { target: '#output1', // 要使用服务器响应更新的目标元素 beforeSubmit: showRequest, // 预提交回调 success: showResponse // 提交后回调 };

// 使用 'ajaxForm' 绑定表单 $('form#webcheck').ajaxForm(选项); });

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

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

I had both the validation and the ajaxform working fine alone, but when I try to combine the form doesn't work properly. I am not that familiar with JQuery and so think the syntax is wrong somewhere. Can anyone spot what Im doing wrong?

The form takes two attempts before it validates, and then the form sends but does not give any response.

// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
target: '#output1', // 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(){
$("form#webcheck").validate();
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(){
alert('Thanks for your comment!');
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2024-08-19 15:44:24
$(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!'); 
}
$(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!'); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文