【问题标题】:Grails Remote Function and AjaxGrails 远程函数和 Ajax
【发布时间】:2010-06-08 22:35:39
【问题描述】:

我正在尝试列出地址和 onChange 事件,我发送地址 ID 并返回用户列表。

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

我称这个 div 为“显示”。

<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 中的 update 属性的理解是,它是在 remoteFunction 调用完成后刷新的 div 的名称。

谢谢。

【问题讨论】:

    标签: grails


    【解决方案1】:

    我会稍微重新组织您的代码以使 Ajax 正常工作:

    1. 将您的 div 内容移动到部分模板中,例如称为 _remoteResponse.gsp

      &lt;g:each in="${users}" status="i" var="C"&gt;
      &lt;h3&gt;${C}&lt;/h3&gt;
      &lt;/g:each&gt;

    2. 修改控制器的 testMe 操作以将响应呈现给模板,例如:

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

    • 确保您在 main.gsp 中设置了 ajax 库,例如:

    &lt;g:javascript library="prototype" /&gt;

    【讨论】:

      猜你喜欢
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      相关资源
      最近更新 更多