Grails当前remoteFunction只能在成功时更新一个div(在错误时更新一)。有时,我想使用一个Ajax调用更新多个div(一旦成功)。除了将remoteFunction链接在一起(即第一个函数成功时调用Javascript函数,调用第二个远程函数)之外,如何做到这一点。。。有没有一种方法可以在没有这种链接的情况下通过ajax更新页面的多个部分?
感谢
您可以通过在javascript中获取onSuccess函数来设置生成的div的html来实现这一点。以下是如何做到这一点的一个很好的例子-http://www.webdeveloperjuice.com/2010/04/01/filling-multiples-divs-by-single-ajax-call-using-jquery/
无法自动完成。
您可以调用两个用分号分隔的远程函数。
<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>
当AJAX请求完成时,您可以设置一些事件。例如:
<g:remoteLink action="show"
id="1"
update="success"
onLoading="showProgress()"
onComplete="updateContent()">Show Book 1</g:remoteLink>
完成后将触发function updateContent
http://grails.org/doc/2.0.x/guide/single.html#ajax
看起来没有办法自动更新两个div。唯一可能的方法是用相同的内容更新两者。