首先验证表单,然后进行ajax调用 [英] validate form first then do ajax call

查看:81
本文介绍了首先验证表单,然后进行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?

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

also Im using this plugin: http://formvalidator.net/#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调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆