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(),否则一直验证不对

  • 相关阅读:
    Web-js中级-11月13日
    Web-js中级-11月12日
    Web-js中级-11月9日
    Web-js中级-11月8日
    Web-js中级-11月7日
    django中自定义了manager函数,使用的时候报错AttributeError: 'Manager' object has no attribute 'title_count'
    django模型篇:一对一、一对多、多对多,添加,批量插入和查询操作
    from django.core.context_processors import crsf报错
    python报错:Exception Value:can only concatenate str (not "bytes") to str
    使用tkinter设计一个简单的加法计算器
  • 原文地址:https://www.cnblogs.com/a757956132/p/3982025.html
Copyright © 2011-2022 走看看