zoukankan      html  css  js  c++  java
  • jquery验证后ajax提交,返回消息如何统一显示的问题

    /* jquery验证后ajax提交,返回消息如何跟jquery验证体系统一显示的问题,网上查了很多资料,都没有找到明确的答案,通过数小时的尝试,终于解决了,现举一个简单的例子,给需要的人参考参考吧*/
    
    <script type="text/javascript">
        $(function () {
            var tt = $("#fmLogin").validate({
                submitHandler: function () {
                    $.ajax({
                        url: "http://localhost:6633/Account/AjaxLogin",
                        cache: false,
                        type: "GET",
                        dataType: 'jsonp',
                        data: $("#fmLogin").serialize(),
                        success: function (result) {
                            if (!result) {
                                var errormap = { SystemMsg: "系统忙,请稍后再试!" }; //注意,map里的key,必须是页面相关标签的name属性值
                                tt.showErrors(errormap, tt.errorlist);                //list就是rules里面定义的那些,注意rules必须包含上面map里的key
                            }
                            if (result.Msg.Code == "VerifyCode") {
                                var errormap = { VerifyCode: result.Msg.Message };
                                tt.showErrors(errormap, tt.errorlist);
                            }
                        }
                    });
                },
                errorPlacement: function (error, element) {
                    error.css("top", element.top + element.height);
                    error.css("left", element.left);
                    if (element.is("#txtVerifyCode"))
                        error.insertAfter(element.parent());
                    else
                        error.insertAfter(element);
                },
                rules: {
                    Account: {
                        required: true,
                        minlength: 6,
                        maxlength: 20,
                    },
                    Password: {
                        required: true,
                        minlength: 6,
                        maxlength: 15
                    },
                    VerifyCode: {
                        required: true
                    },
                    SystemMsg: {    //如果要用来绑定消息,就必须定义,哪怕什么验证都不做,注意必须是绑定消息的某标签的name属性值
                    }
                }
            });
        });
    </script>
    

  • 相关阅读:
    HDU 3709 数位dp
    Educational Codeforces Round 64 (Rated for Div. 2)-C. Match Points
    POJ 1845乘法逆元+约数和
    POJ3696 欧拉定理
    NC24953 树形dp(最小支配集)
    Codeforces 1173 C 思维+模拟
    Codeforces 1324F 树形dp+换根
    codeforces-1285D(字典树)
    面向纯小白的CLion(C++)基于Windows的安装配置教程
    HDU-2825Wireless Password(AC自动机+状压DP)
  • 原文地址:https://www.cnblogs.com/foren/p/6009101.html
Copyright © 2011-2022 走看看