2010-06-08 45 views
0

我想列出地址和onChange事件我發送地址ID並返回用戶列表。Grails遠程函數和Ajax

<g:select name="AddressID" from="${address}" optionKey="id" optionValue="address" 
       onchange="${ remoteFunction(
          action:'testMe', 
          params:'\'id=\' + this.value' , 
          update:'show')}"> 
     </g:select> 

我把這個div叫做「show」。

<div id="show"> 
    <g:each in="${users}" status="i" var="C"> 
     <h3>${C}</h3> 
    </g:each> 

</div> 

然而,當我點擊列表框,我得到以下錯誤的項目: description The requested resource (/MyTest/WEB-INF/grails-app/views/test/testMe.jsp) is not available.

我一個remoteFunction內的更新屬性的理解是,它是獲取div的名字remoteFunction調用完成後刷新。

謝謝。

回答

2

我會重新整理自己的一點點得到阿賈克斯工作代碼:

  1. 將您div內容到一個局部模板,所謂的,比如說,_remoteResponse.gsp

    <g:each in="${users}" status="i" var="C">
    <h3>${C}</h3>
    </g:each>

  2. 修改您的控件米勒的testMe行動來渲染一個模板的反應,是這樣的:

render (template:'remoteResponse', model:[users:['mike,tim']])

  • 確保您有一個Ajax庫設置在main.gsp,如:

<g:javascript library="prototype" />