I am using jquery.validate plugin for checking username availability
if user type sample
i need to display error as
sample is available
or sample is not availabl开发者_StackOverflow社区e
$("#form_id").validate({
rules: {
username: {
required: true
}
},
messages:{
username: {
required: "username should not be blank",
remote: $('#username_id').val()+"is already available"
}
}
});
Remote error displays
is not available
i expect
sample is not available
Updated: I had tried this
remote: jQuery.format("{0} is already available")
Once i click submit button error is displayed as sample is not available
if i click submit again and again error becomes
server_pg.php is not available
i dont know why jquery.validate misbehaving like this...
I don't see any remote
rule in your definition. Try:
$("#form_id").validate({
rules: {
username: {
required: true,
remote: 'test.cgi'
}
},
messages:{
username: {
required: 'username should not be blank',
remote: $.format('{0} is already available')
}
}
});
Also make sure that your server side script returns JSON content type with true
or false
value. Finally make sure that the username input has id="username_id"
as specified in the messages.
If you just remove this from messages:
remote: $('#username_id').val()+"is already available"
Then anything but true
will be displayed as the message, so just have your server return exactly:
"nameChecked is already avaialable"
Return only this (or whatever message), quotes included and that string gets displayed. This also ensures you're getting what was checked, not the current value.
精彩评论