Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:46:02+00:00 2026-05-31T06:46:02+00:00

How do I map calls to a Grails controller from a Javascript method? I

  • 0

How do I map calls to a Grails controller from a Javascript method? I see a method using PHP, but not with grails:

function getSelected(checkList)
        {
            var idList = new Array();
            var loopCounter = 0;
            //find all the checked checkboxes
            jQuery("input[name=" + checkList + "]:checked").each
            (
              function()
              {
                //fill the array with the values
                idList[loopCounter] = jQuery(this).val();
                loopCounter += 1;
              }
            );

            //call here

        }

Edit:

${remoteFunction(controller:"person", action:"runThroughAll", params:"[ids:idList]")}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:46:03+00:00Added an answer on May 31, 2026 at 6:46 am

    So, I feel like there are sort of two things you’re asking here. I’m going to tackle them both. First, how do you get the URL right for a call to a grails controller from JavaScript? In my GSP page (I do it in my main layout but whatever), I like to do this little trick:

    <script>
    myapp.url.root = "<g:resource dir='' file='' />" + "/";
    </script>
    

    That will give you the base root of your app wherever it’s deployed. Then, you can build your URLs in JavaScript:

    myurl = myapp.url.root + “path/to/controller”

    Then make a jQuery ajax call using that url.

    Then make sure that your controller is set up to respond to whatever URL pattern you’ve just expressed.

    The second question appears to be, “how can I send back an HTML fragment”?

    Inside the controller itself, take the parameters from the request, use it to figure out whatever you need, then render the gsp, passing in the model you’ve created. It will look something like this:

    def show() {
       def data = [hypothesis : metadataService.getHypothesis(params.id) as JSON]
       render(view:"create", model:data)
    }
    

    Then in jQuery, your success handler will get as an argument the returned response, which you can then inspect/manipulate/add to the dom.

    Hopefully all that made sense. If I glossed over something or didn’t answer the question you were asking, let me know.

    EDIT: For future reference, here is the javascript method rewritten which we arrived at in chat:

    function getSelected(checkList){ 
    var idList = $("input[name='" + checkList + "']:checked").map(function(){ return $(this).val(); }); 
    
    $.ajax({ 
    url: "/path/to/controller", 
    type:"POST", 
    data:{ids:JSON.stringify(idList)} 
    success:mySuccessFunction 
    }); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

map.root :controller => main, :action => index is not redirecting the main controller to
I'm gluing together a number of system calls using the Amazon Elastic Map Reduce
Before I was trying to map my classes and namespaces, by using static calls
I have multiple calls to many RESTful services. I translate to PHP using native
I am tring to map json data using Gson from a URL to my
I'm trying to redirect API calls to api.php with parameters, but it doesn't work.
A Map maps from keys to values and provides quick access based on the
Custom map is broken on satellite view, does not show satellite imagery. Any ideas,
I'm attempting to add a method to a grails domain class, e.g. class Item
I have a computing map (with soft values ) that I am using to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.