Peter
Peter

Reputation: 29857

Best way to update multiple divs with different values from the response of <g:remoteLink>?

The documentation of remoteLink allows you to update a single div easily with the response from the server, but I'd like to return several values (via JSON) and update more than one spot on the page. How would I do this? Here is a contrived example, note I am using the JQuery plugin so I believe the response is available in 'data', not in 'e' as the grails documentation says, but my client side skills are pretty weak and the example call to updateTwo could be wrong so feel free to correct me.

GSP:

<g:remoteLink controller="ajaxexample" action="test" update="assumeIcantUseThis" onSuccess="updateTwo(data, 'DivId1', 'DivId2')"></g:remoteLink>

<g:javascript>
 function updateTwo(?) {
  ??
 }
</g:javascript>

Controller

class AjaxexampleController {
  def test = {
        def example = ["v1":1,"v2":2];
        render example as JSON;
    }

} 

Upvotes: 0

Views: 641

Answers (1)

nuoymit
nuoymit

Reputation: 153

I would avoid using the Grails remote/AJAX tags. I have found them usable in only straightforward scenarios.

The best way to learn what I am talking about is to look at the rendered HTML of your view. Use a tool like Firebug (Firefox) or developer console (IE9, Chrome) to look at the output of the grails remote tags. You will see that all they turn out to be are links/forms with onClick or onSubmit attributes.

From there you can work with the generated JavaScript to customize the function to your needs.

Upvotes: 1

Related Questions