Reputation: 51
I am using grails 2.3.4 and according to grails docs there is both <g:remoteFunction>
and ${remoteFunction}
.I am trying to send values from params to the controller but it is returning null value please help the code is :
The gsp page code is :
<div id="test"></div>
<input type="text" name="myname" id="myname">
<input type="button" name="view" value="view" onclick="myFunction()">
and the javascript function is:
function myFunction(){
var name=$("#myname").val();
<g:remoteFunction controller="test" action="testreport" update="test" params="{n:name}"></g:remoteFunction>
}
and the controller code is
def testreport(){
println"test"
println "params value is "+params.n
println params
}
and the output is :
test
params value is null
[action:testreport, format:null, controller:test]
Upvotes: 0
Views: 1531
Reputation: 8587
I have used g:remoteFunction in many ways, within gsp - you could use:
<button id=boxbtn onclick="<g:remoteFunction controller="Controller"
action="action" params="${[id:inputid, sortby:sortby, order:order, s:s,
userchoice:'yes', viewtype:'na', offset:offset, max:max]}" update="siteContent" />">
UPDATE try using this as your myFunction instead of what you had above
function myFunction(){
var name = document.getElementById('myname');
<g:remoteFunction controller="test" action="testreport" update="test" params="${[n:name]}"></g:remoteFunction>
}
Upvotes: 3
Reputation: 9072
You're messing things up. is executed on the server side when the view gets rendered. Your Javascript variable name
will have a value when the browser executes your Javascript on the client side. There is a typo in your code. Instead of
<g:remoteFunction controller="test" action="testreport" update="test" params="{n:name}"></g:remoteFunction>
use
<g:remoteFunction controller="test" action="testreport" update="test" params='\'n=\' + name'></g:remoteFunction>
and if you have more than one param to submit use
<g:remoteFunction controller="test" action="testreport" update="test" params='\'n=\' + name¶mName=\' + varName\''></g:remoteFunction>
Upvotes: 1