zoukankan      html  css  js  c++  java
  • 普通Jquery的ajax判断重复和formvalidator的ajaxValidator区别

    示例:1.ajax版:

          $("#txtTitle").blur(function () {
                    $.ajax({
                        type: "GET",
                        url: "Handler.ashx?NewsAdd=1&txtName=" + encodeURIComponent($(this).val()) + "",
                        data: null,
                        success: function (msg) {
                            if (msg != "") {
                                flag = false;
                                alert("不要重复添加!");
                            }
                            else
                                flag = true;
                        },
                        onerror: function () { alert("error") }
                    });
                });

    2.ajaxValidator版

               $("#txtName").formValidator({ onshow: "请填写物品名称", onfocus: "物品名称必须输入" }).inputValidator({ min: 1, max: 50, empty: { leftempty: false, rightempty: false, emptyerror: "不能有空格" }, onerror: "物品名称输入错误,可能长度超标" }).ajaxValidator({
                    url: oldValue == "" ? "Handler.ashx?GoodsAdd=1" : "Handler.ashx?GoodsEdit=1&oldValue=" + oldValue + "",
                    addidvalue: true,
                    success: function (data) {
                        if (data == "1")
                            return false;
                        else
                            return true;
                    },
                    buttons: $("#lbSubmit"),
                    error: function () { alert("出错了"); },
                    onerror: "请不要重复添加",
                    onwait: "正在验证是否重复,请稍候..."
                }).defaultPassed();//修改时候加上

    要注意的地方:

    1.ajaxValidator传参时候通过$(id)得到的永远是空值。所以,用 addidvalue: true的解决方案。自动在url上追controlId=idVlaue;

    2.$.ajax中onerror代表服务器程序错误状态,而ajaxValidator中代表,success状态下,return false的情况。ajaxValidator中代表服务器错误是error。

    3.ajaxValidator修改时候,验证重复时候要加上defaultPassed(),否则一直验证不对

  • 相关阅读:
    路由器配置——基于链路的OSPF简单口令认证
    路由器配置——基于区域的OSPF,MD5认证
    将博客搬至CSDN
    爬虫入门【11】Pyspider框架入门—使用HTML和CSS选择器下载小说
    爬虫入门【10】Pyspider框架简介及安装说明
    【Python基础】装饰器的解释和用法
    爬虫入门【9】Python链接Excel操作详解-openpyxl库
    爬虫实战【13】获取自己的动态代理ip池
    爬虫实战【12】使用cookie登陆豆瓣电影以及获取单个电影的所有短评
    爬虫实战【11】Python获取豆瓣热门电影信息
  • 原文地址:https://www.cnblogs.com/a757956132/p/3982025.html
Copyright © 2011-2022 走看看