我正在使用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调用
发布评论