Grails: Updating multiple page elements with ajax

Tag: grails Author: jhyinkang Date: 2009-09-08

It seems that with g:formRemote and g:submitToRemote, I can only specify one update target div. What would be a viable strategy for updating multiple divs?

Can you please provide an example for that... i am not sure what you want to achieve.

Other Answer1

if you want to stick with using the g:formRemote tags to perform your ajax, it might not be possible. Why not write some jQuery, and roll a custom ajax update? it couldnt be easier!


Everything's possible with jQuery!

Other Answer2

You could instead of using update, use onSuccess and parse the response and update the elements you need to update like this:

<g:formRemote name='loginForm' url="[action:'login']"
    onSuccess='loginOK(e)' >
  <!-- form fields -->
  function loginOK( resp ) {
    // parse the resp.responseText and update


Or you could just use jQuery and roll your own like the previous answer suggests.

If you want to update one element based on success vs another on failure you can use a map like this:

<g:formRemote name='loginForm' url="[action:'login']" update="[success:'message',failure:'error']">

Other Answer3

there is asolution to this grails problem, you can use taconite, where taconite allows to update muliple elements with one single ajax call

and there is another solution posted at someone's blog, but my reputation does only allow me to post one link here on developark!!!

so i give the title of the blog post "Updating multiple page elements with Grails and Ajax"

Other Answer4

From the grails doc for g:formremote, , you can use the onSuccess callback to define a js function for a succesfull submit, so you can update all your target elements within that function, otherwise making an ajax call yourself also is a good option.