Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
Is it possible to execute a Grails dynamic finder query from JavaScript block

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);
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

def findUser() {
    def fullName = User.findByUsername(params.username)?.fullName
    return fullName
}

and then use ajax function in your gsp

$('.usrname').blur(function(){

    var username = $(this).val();
    var URL ="/yourController/findUser/?username=" + username;                                                                          

    $.ajax({
        url:URL,
        success: function(resp){
            alert(resp);
        }
    });
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!