Tuesday, 3 December 2013

Calling a method from server side while jquery validation

You can use remote for calling server side method.
As in code given below:

Javascript code:

$(function() {
        $("#add").click(function() {
$('#addusers').validate(
      {
rules : {
          userName : {
required : true,
remote : '/abc/useravailability'
},
emailid : {
required : true,
email : true
},
password : {
required : true
}
},
messages : {
userName : {
remote : jQuery
.format("Username is not available")
}
},
highlight : function(element) {
$(element).closest(
'.control-group')
.removeClass(
'success')
.addClass('error');
},
success : function(element) {
element
.text('OK!')
.addClass('valid')
.closest(
'.control-group')
.removeClass(
'error')
.addClass('success');
}
});
});


And server side method:
@RequestMapping(value = "/useravailability", method = RequestMethod.GET)
public @ResponseBody
boolean getUserAvailability(@RequestParam("userName") String name) {
//write some code
return boolean;
}


No comments:

Post a Comment