zoukankan      html  css  js  c++  java
  • 修改jquery的remote让前段显示服务器错误信息

    remote: function (value, element, param) {
    //param 是你的rules中规定的参数,在这里肯定是remote中的参数了
    //value是你输入的值
    //element是你操作的元素,标签

    if (this.optional(element)) {
    return "dependency-mismatch";
    }

    var previous = this.previousValue(element),
    validator, data;

    if (!this.settings.messages[element.name]) {
    this.settings.messages[element.name] = {};
    }
    previous.originalMessage = this.settings.messages[element.name].remote;
    this.settings.messages[element.name].remote = previous.message;

    param = typeof param === "string" && {url: param} || param;

    if (previous.old !== value) {
    previous.old = value;
    validator = this;
    this.startRequest(element);
    data = {};
    data[element.name] = value;//输入框中的数据


    $.ajax($.extend(true, {
    url: param,
    mode: "abort",
    port: "validate" + element.name,
    dataType: "json",
    data: data,
    context: validator.currentForm,
    success: function (response) {


    var valid = response['value'] === true || response['value'] === "true", errors, message, submitted;

    validator.settings.messages[element.name].remote = previous.originalMessage;
    if (valid) {
    submitted = validator.formSubmitted;
    validator.prepareElement(element);
    validator.formSubmitted = submitted;
    validator.successList.push(element);
    delete validator.invalid[element.name];
    validator.showErrors();
    } else {
    errors = {};
    message = response['msg'] || validator.defaultMessage(element, "remote");
    errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
    validator.invalid[element.name] = true;
    validator.showErrors(errors);
    }
    previous.valid = valid;
    validator.stopRequest(element, valid);
    }
    }, param));
    return "pending";
    }
    }
  • 相关阅读:
    学习canvas过程中的小菜鸟
    小菜鸟谈html语义化
    mui常用方法
    mui的侧滑菜单如何禁用手势侧滑
    ajax 传递数组参数
    LNMP状态管理命令
    LNMP相关软件目录及文件位置
    ubuntu常用命令
    Ubuntu设置允许root用户登录
    linux一键安装web环境(sh-1.3.0)
  • 原文地址:https://www.cnblogs.com/bergus/p/4536372.html
Copyright © 2011-2022 走看看