あなたは以下のようなメソッドを追加することができます。
$.validator.addMethod("fullRemote", function(value, element, params) {
if (this.optional(element))
return "dependency-mismatch";
var previous = this.previousValue(element);
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;
if(params.onStart) params.onStart(element);
params = typeof params == "string" && {url:params} || params;
if (this.pending[element.name]) {
return "pending";
}
if (previous.old === value) {
return previous.valid;
}
previous.old = value;
var validator = this;
this.startRequest(element);
var data = {};
data[element.name] = value;
$.ajax($.extend(true, {
url: params,
mode: "abort",
port: "validate" + element.name,
dataType: "json",
data: data,
success: function(response) {
validator.settings.messages[element.name].remote = previous.originalMessage;
var valid = response === true;
if(params.onFinish) params.onFinish(element, valid);
if (valid) {
var submitted = validator.formSubmitted;
validator.prepareElement(element);
validator.formSubmitted = submitted;
validator.successList.push(element);
validator.showErrors();
} else {
var errors = {};
var message = response || validator.defaultMessage(element, "remote");
errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
validator.showErrors(errors);
}
previous.valid = valid;
validator.stopRequest(element, valid);
}
}, params));
return "pending";
}, "The value you entered is already in use.");
を次に "リモート" とほぼ同じ、それを使用し、以下のように:
...
rules: {
email: {
required: true,
email: true,
fullRemote: {
url: "../emailavailable",
type: "post",
onStart: function(e){
var loading = $('#ajaxLoading');
loading.appendTo($(e).parent());
alert($(e).val());
},
onFinish: function(e, valid){
var loading = $('#ajaxLoading');
loading.remove();
return true;
}
}
}
},
messages: {
email: {
fullRemote: "email address is already in use."
}
},
...
は、私は実現しませんでした、ありがとうございましたそれは簡単でした! –
Kasper scr4veが役に立った場合は、彼の答えが正しいことを示すチェックマークをチェックしてください。 – Brad