-2
我試圖找出一旦遠程函數的回調用戶名或電子郵件地址,如果返回的數據等於「n」它應該觸發消息被顯示。jQuery驗證成功的觸發消息
JS:
$(document).ready(function() {
var validator = $("form").validate({
rules: {
username: {
minlength: 6,
maxlength: 12,
remote: {
type: 'post',
url: 'register/is_username_available',
data: {
'username': function() {
return $('#username').val();
}
},
dataType: 'json',
success: function(data) {
alert(data);
if (data == 'y') {
alert('available');
}
else {
alert('no available');
}
}
}
},
email_address: {
email: true,
remote: {
type: 'post',
url: 'register/is_email_available',
data: {
'email_address': function() {
return $("#email_address").val();
}
},
dataType: 'json',
success: function(data) {
alert(data);
if (data == 'y') {
alert('available');
}
else {
alert('no available');
}
}
}
}
},
messages: {
username: {
remote: 'The username is already in use'
},
email_address: {
remote: 'There is already an account set up that uses that email address!'
}
}
});
});
我建議你改述你的問題;我認爲它可以更清晰。 –
好吧,我改寫了它。 –
現在有關於此的任何想法? –