Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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:</p> <pre><code>&lt;script&gt; myapp.url.root = "&lt;g:resource dir='' file='' /&gt;" + "/"; &lt;/script&gt; </code></pre> <p>That will give you the base root of your app wherever it's deployed. Then, you can build your URLs in JavaScript:</p> <p>myurl = myapp.url.root + "path/to/controller"</p> <p>Then make a jQuery ajax call using that url.</p> <p>Then make sure that your controller is set up to respond to whatever URL pattern you've just expressed. </p> <p>The second question appears to be, "how can I send back an HTML fragment"?</p> <p>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:</p> <pre><code>def show() { def data = [hypothesis : metadataService.getHypothesis(params.id) as JSON] render(view:"create", model:data) } </code></pre> <p>Then in jQuery, your success handler will get as an argument the returned response, which you can then inspect/manipulate/add to the dom.</p> <p>Hopefully all that made sense. If I glossed over something or didn't answer the question you were asking, let me know.</p> <p>EDIT: For future reference, here is the javascript method rewritten which we arrived at in chat:</p> <pre><code>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 }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload