修改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";
}
}
posted @ 2015-05-28 16:58  白云辉  阅读(229)  评论(0编辑  收藏  举报