码迷,mamicode.com
首页 > Web开发 > 详细

修改jquery的remote让前段显示服务器错误信息

时间:2015-05-28 17:48:39      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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";
}
}

修改jquery的remote让前段显示服务器错误信息

标签:

原文地址:http://www.cnblogs.com/bergus/p/4536372.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!