I am using Grails 2.5.2. I am trying to execute a dynamic finder query from JavaScript block with a variable. But the JS variable is not recognized. How can I do this?
My attempts as below:
$(".usrname").blur(function() {
var username = $(this).val();
var fullName = "${User.findByUsername(username)?.fullName}";
alert(fullName);
});
it won't work because it's rendered into html before your variable username value is known.
you have to use an action in your controller
and then use ajax function in your gsp