结合 jquery validate 和 ajaxForm 插件
我的验证和 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)