Reputation: 6115
The Grails current remoteFunction can only update one div on success (and one on error). There are times where I want to update multiple divs (on success) using a single Ajax call. How can one do this, other than to chain the remoteFunctions together (i.e. where the first one calls a Javascript function on success, which invokes the second remote function). ... Is there a way to update multiple parts of a page via ajax without this type of chaining?
Thanks
Upvotes: 3
Views: 7278
Reputation: 41
You could call two remote functions separated by semi colon.
<g:select id='releaseVersion' name="releaseVersion" noSelection="['0':'--Select--']" from='${new Alarm().constraints.releaseVersion.inList}' onchange="${remoteFunction(controller:'alarm', action:'updateComponentByRelease',params:'\'selectedValue=\' + this.value', update:'component')};
${remoteFunction(controller:'alarm',action:'updateDiscriminatorByComponent', params:'\'selectedValue=\' + this.value',update:'subsystem')};"></g:select>
Upvotes: 4
Reputation: 3532
You can do this by getting your onSuccess function in javascript to set the html of the resulting divs. Here is a good example of how to do this - http://www.webdeveloperjuice.com/2010/04/01/filling-multiples-divs-by-single-ajax-call-using-jquery/
Cannot be done automatically.
Upvotes: 4
Reputation: 92334
There are events you can set for when the AJAX request finishes. For example:
<g:remoteLink action="show"
id="1"
update="success"
onLoading="showProgress()"
onComplete="updateContent()">Show Book 1</g:remoteLink>
Will trigger function updateContent
when it completes http://grails.org/doc/2.0.x/guide/single.html#ajax
It doesn't look like there's a way to automatically update two divs. The only possible way it could do it is by updating both with the same content.
Upvotes: 0