如何在 Grails 3.2.3 中使用 ajax

Say*_*yem 2 ajax grails taglib ajaxtags grails3

我在 grails 2.4.7 工作。最近我转移到 grails 3.Previously 我使用 grails 自定义标签进行 ajax 调用,如 remoteFunction、formRemote。这个标签不适用于最新版本。谁能告诉我使用 ajax 的最佳方法最新版本。

Par*_*rth 5

是的,从 2.4.xg:remoteFunction开始,grails 已弃用。

看到这个。http://docs.grails.org/2.4.1/ref/Tags/remoteFunction.html

不过,您始终可以使用如下所示的 javascript/jQuery ajax 函数,它的作用完全相同。

<g:javascript>
  function callMyAjax(){
    $.ajax({ 
      url:'${g.createLink( controller:'yourcontroller', action:'youraction')}',
      data:{ 
           param1:param1,
           param2:param2
      }
    });
  }
 </g:javascript>

 <input type="button" onclick="callMyAjax()"/>
Run Code Online (Sandbox Code Playgroud)