首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在验证输入之前验证是否显示成功

在验证输入之前验证是否显示成功
EN

Stack Overflow用户
提问于 2013-07-03 20:16:25
回答 1查看 59关注 0票数 0

我有一个表单,我在该表单上使用jQuery验证来验证输入是否完整。但是,现在的情况是,验证器正在显示消息,但它也在向boxesadd.php发出Ajax调用。我的印象是,这个ajax调用是在成功验证之后才进行的。当输入还没有完成时,它为什么会到达Ajax事件。谢谢

jquery代码

代码语言:javascript
运行
复制
$(function () {

    $.validator.setDefaults ({

        errorClass: 'form_error',
        errorElement: 'div'
    });

    $("#BA_boxform").validate({
        rules: {
            BA_customer: {
                required: true
            },
            customerdept: {
                required: true
            },
            customeraddress: {
                required: true
            },
            BA_service: {
                required: true
            },
            BA_box: {
                required: true
            },
            BA_destdate: {
                required: true
            },
            BA_authorised: {
                required: true
            }
        },
        messages: {
            BA_customer: {
                required: '<br />* required: You must select a customer'
            },
            customerdept: {
                required: "<br />* required: You must select a department"
            },
            customeraddress: {
                required: "<br />* required: You must select a customer address"
            },
            BA_service: {
                required: "<br />* required: You must select a service level"
            },
            BA_box: {
                required: "<br />* required: You must enter a box number for intake"
            },
            BA_destdate: {
                required: "<br />* required: You must enter a destruction date"
            },
            BA_authorised: {
                required: "<br />* required"
            }
        }
    });

    $('#BA_boxform').on('submit', function () {

        var formdata = $('#BA_boxform').serialize() + '&submit=' + $(this).val();

        //alert(formdata);
        $.ajax({
            type: "POST",
            url: "/domain/admin/requests/boxes/boxesadd.php",
            data: formdata,
            dataType: 'json',
            success: function (msg) {
                //alert(msg);
                if (typeof msg.boxerrortext !== "undefined" && msg.boxerrortext == "You must enter a box for intake") {
                    $("#BA_addbox").html(msg.boxerrortext);
                } else {
                    $("#BA_addbox").html("You have successfully added box(es) " + '<span style="font-weight: bold;color:black;">' + msg.box + '</span>' + ' to the archive.' + '<br />' + 'You may now close this window or input more boxes.');
                    $("#BA_boxform").get(0).reset();
                }
                //$("#confirm_department").hide();

                /*
               var $dialog = $('<div id="dialog"></div>')
               .html('Your intake was successfully submitted and will be viewable in the reporting area.<br /><br />Thank you.');
               $dialog.dialog({
               autoOpen: true,
               modal: true,
               title: 'Box intake submission successfull',
               width: 400,
               height: 200,
               draggable: false,
               resizable: false,
               buttons: {
               Close: function() {
               $( this ).dialog( "close" );
               }
               }
               });
               */
                //alert(msg);
                //console.log(msg);
                //$("#BA_addbox").html(msg.box);

                //$("#formImage .col_1 li").show();
                //$("#BA_boxform").get(0).reset();
                //$("#boxaddform").hide();
            }
        });
        return false;
    });
});
EN

回答 1

Stack Overflow用户

发布于 2013-07-03 21:01:52

只需在进行ajax调用之前检查您的消息是否为空。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17447728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档