How to catch and show custom error message from the server side on the html page?
function getAlertMessage() {
$.ajax({
type : "POST",
url : "getAlert.do",
success : function(data) {
data.alertmsg //How to set this msg to validatename property in messages Attribute
},
error : function() {
alert("No Court No details found");
}
});
}
$(document).ready(function() {
$("#register-form").validate({
rules : {
username : {
required : true,
validname : true,
minlength : 4
}
},
messages : {
username : {
required : "Please Enter UserName",
validname : getAlertMessage(), //it does not worked here
minlength : "UserName is Too Short"}},
errorPlacement : function(error,element) {
$(element).closest('.form-group').find('.help-block').html(
error.html());
},
highlight : function(element) {
$(element).closest('.form-group')
.removeClass('has-success')
.addClass('has-error');
},
unhighlight : function(element,
errorClass, validClass) {
$(element).closest('.form-group')
.removeClass('has-error')
.addClass('has-success');
$(element).closest('.form-group')
.find('.help-block').html('');},
submitHandler : function(form) {
form.submit();}});});
validateinside the success handler, or you change that setting in the success handler by accessing$("#register-form").validate().settings