Since g:remoteFunction in Grails 2.4.X is deprecated what should i use instead?

后端 未结 2 492
广开言路
广开言路 2020-12-21 01:16

Since g:remoteFunction is deprecated what should I use instead? And please give an example.

相关标签:
2条回答
  • 2020-12-21 01:19

    you should use your own javascript AJAX functions, as they provide way more flexibility

    EXAMPLE

    used to be:

    <input type="button" value="go!" onclick="${g.remoteFunction( controller:'my', action:'go', params:[..] )}"/>
    

    should be (for example in JQuery):

    <g:javascript>
      function go(){
        $.ajax({ 
          url:'${g.createLink( controller:'my', action:'go', params:[..] )}',
          data:{ param1:param1 }
        });
      }
     </g:javascript>
    
     <input type="button" value="go!" onclick="go()"/>
    
    0 讨论(0)
  • 2020-12-21 01:32

    Just to elaborate on Injecteers answer actually the data:{} is what is posting information to it so may clash with params:[..]} :

    <g:javascript>
      function go(){
       var javaScriptVariable='123'
        $.ajax({ 
          url:'${g.createLink( controller:'my', action:'go')}',
          data:{ 
            param1: "${params.params1}",
            param2: javascriptVariable 
          }
        });
      }
     </g:javascript>
    

    data:{} can also be data: $('form').serialize(); where serialize function grabs all the form elements and serializes it for you as params to be passed back.

    0 讨论(0)
提交回复
热议问题