Grails RemoteForm、Ajax 不起作用

发布于 2024-12-10 05:52:31 字数 1902 浏览 1 评论 0原文

我是 Grails 新手,并且在 Ajax 方面遇到了一些麻烦(所以我可能会错过一些东西)。在我的主 gsp 上,我想要一个选择框,当我单击其选项时,会在同一页面上出现另一个字段来选择其他内容。由于第二部分的内容是动态的,所以我需要一些Ajax。反正我还没有成功。这是我的代码:

main.gsp

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="layout" content="main" />
    <title>Sample title</title>
    <g:javascript library="jquery"/>
  </head>
  <body>
    <h1>Selection de l'email</h1>
    <div class="dialog">
        <g:select name="selectTemplate"
                  from="${templateCategories}"
                  value="category"
                  noSelection="['':'--- choisissez un modèle ---']"
                  onchange="${remoteFunction(
                      controller:"email"
                      action:"printTestTemplate"
                      update:"listTemplates"
                      params:'\'category=\'+this.value'
                      )}"
                  />
          <div id="listTemplates">RRR</div>
      </div>
   </body>
</html>

EmailController

def printTestTemplate = {
    println params.category //doesn't print anything
    println "YEAAAAAAAAAH"  //the same
    render(view:"formSelectTemplate", model:[templates:EmailTemplate.findByCategory(params.templateCategory)])
}

formSelectTemplate.gsp

<h1>YOUHOUUU !</h1>

我都尝试调用视图或模板(当然通过重命名 gsp),但没有任何效果。不过我不太明白,我遵循了官方文档。请注意,HTML 结果没有在选择框上创建任何事件,并且 Firebug 告诉我没有 404。所以我一定在创建框时错过了一些东西。

选择 HTML 格式的结果:

<select id="selectTemplate" name="selectTemplate">  
    <option value="Refus">Refus</option>  
    <option value="Informations complémentaires">Informations complémentaires</option>  
</select>  

I'm new on Grails and I have some troubles with Ajax (so I could have missed something). On my main gsp I want a select box, that, when I click on its options, makes appear another field on the same page to select other things. As the content in the second part is dynamic, I need somme Ajax. Anyway I haven't succeed yet. Here is my code :

main.gsp

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="layout" content="main" />
    <title>Sample title</title>
    <g:javascript library="jquery"/>
  </head>
  <body>
    <h1>Selection de l'email</h1>
    <div class="dialog">
        <g:select name="selectTemplate"
                  from="${templateCategories}"
                  value="category"
                  noSelection="['':'--- choisissez un modèle ---']"
                  onchange="${remoteFunction(
                      controller:"email"
                      action:"printTestTemplate"
                      update:"listTemplates"
                      params:'\'category=\'+this.value'
                      )}"
                  />
          <div id="listTemplates">RRR</div>
      </div>
   </body>
</html>

EmailController

def printTestTemplate = {
    println params.category //doesn't print anything
    println "YEAAAAAAAAAH"  //the same
    render(view:"formSelectTemplate", model:[templates:EmailTemplate.findByCategory(params.templateCategory)])
}

formSelectTemplate.gsp

<h1>YOUHOUUU !</h1>

I've both tried to call a view or template (by renaming the gsp of course), but nothing worked. Nevertheless I don't understand, I followed the official doc. Notice that the HTML result creates no event on the select box, and that Firebug tells me there is no 404. So I must have missed something in the creation of the box.

select result in HTML :

<select id="selectTemplate" name="selectTemplate">  
    <option value="Refus">Refus</option>  
    <option value="Informations complémentaires">Informations complémentaires</option>  
</select>  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮光沉寂 2024-12-17 05:52:31

您是否忘记了 remoteFunction 调用的参数之间的逗号?像这样:

onchange="${remoteFunction(controller:"email",
                           action:"printTestTemplate",
                           update:"listTemplates",
                           params:'\'category=\'+this.value' )}"

Did you forget comas between the arguments of your remoteFunction call ? like this:

onchange="${remoteFunction(controller:"email",
                           action:"printTestTemplate",
                           update:"listTemplates",
                           params:'\'category=\'+this.value' )}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文