jquery validate后台验证

给个比较详细的链接http://www.cnblogs.com/weiqt/articles/2013800.html

我主要说说如何通过remote来后台校验

贴出代码 

js

$("#addform").validate({
                rules: {
                    DictionaryName: {
                        required: true,

                        remote: {
                            url: "AD_DATA_DICTIONARY.ashx?type=checkName&&stasts=Add",
                            type: "post",
                            dataType: "json",
                            data: {
                                DictionaryName: function () {
                                    return $("#DictionaryName").val();
                                }
                            }
                        }
                    }
                },
                messages: {
                    DictionaryName: "字典名已存在"
                }
            });
View Code


后台部份代码

 

case "checkName":
                    string status=context.Request["stasts"];
                    string dictionaryName=context.Request["dictionaryName"];
                    if (status == "Add")
                    {
                        if (dalADD.getNameCount(dictionaryName) > 0) context.Response.Write("false");
                        else context.Response.Write("true");
                    }
                    else {
                        if (dalADD.getNameCount(dictionaryName) > 1) context.Response.Write("false");
                        else context.Response.Write("true");
                    };
                    break;
View Code

看清楚后台返回的数据格式只能是字体串形式的"true"和"false";

posted on 2013-07-06 15:34  ZombieSir  阅读(591)  评论(0编辑  收藏  举报