首先验证表单,然后进行ajax调用

编程入门 行业动态 更新时间:2024-10-12 05:47:00
本文介绍了首先验证表单,然后进行ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用jquery验证插件来验证我的表单.但是仍然有一些字段需要自定义验证.

Im using a jquery validation plugin to validate my form. But there are still some fields that need custom validation.

奇怪的是.提交时,首先检查我的选择框确认(如果可以),然后由于$ .validate();所有字段变为红色.如果什么都没有填写,但仍然继续进行ajax调用,这是为什么呢?

The strange thing is. When submiting it checks my select box validation first when this is OK then all field turn red because of the $.validate(); if nothing is filled in but still it proceeds with the ajax call...... why is this?

我也正在使用此插件: formvalidator/#configuration 我已经尝试了回调但由于某种原因,它仍然不会返回false并继续执行ajax.

also Im using this plugin: formvalidator/#configuration i have tried the callbacks but for some reason it still not returns false and proceeds with ajax.

$( "#registration-form" ).submit(function( event ) { event.preventDefault(); $.validate(); //Check dropdown if(document.getElementById('foodassoonas').selectedIndex == 0) { $('#dateerrormsg').html('not ok'); $("#foodassoonas").css({"border":"1px solid red"}); return false; } $.post(jssitebaseUrl+'/ajaxFile.php',{'contactemail':contactemail,'action':'checkOrderEmailId'}, function(output){ alert(output); if(output == 'already' && contactpassword !=""){ $("#createUserError").addClass('errClass1 margin0'); $("#createUserError").html('not ok'); $("#createUserError").show(); return false; }else if(output == 'gotopayment' || (output == 'already' && contactpassword =="")){ document.checkoutform.submit(); } return false; }); return false; });

推荐答案

尝试一下

$.validate({ onError : function() { alert('Validation failed'); return false; } });

更多推荐

首先验证表单,然后进行ajax调用

本文发布于:2023-10-27 04:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532278.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!