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>


posted @ 2017-05-07 14:28  claireyuancy  阅读(742)  评论(0编辑  收藏  举报