我正在使用 grails 2.3.4,根据 grails 文档,有 <g:remoteFunction>
和${remoteFunction}
。我试图将参数中的值发送到 Controller ,但它返回空值,请帮助代码是:
gsp页面代码是:
<div id="test"></div>
<input type="text" name="myname" id="myname">
<input type="button" name="view" value="view" onclick="myFunction()">
JavaScript函数是:
function myFunction(){
var name=$("#myname").val();
<g:remoteFunction controller="test" action="testreport" update="test" params="{n:name}"></g:remoteFunction>
}
Controller 代码是
def testreport(){
println"test"
println "params value is "+params.n
println params
}
输出是:
test
params value is null
[action:testreport, format:null, controller:test]
最佳答案
我在 gsp 中以多种方式使用了 g:remoteFunction - 你可以使用:
<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" />">
更新 尝试使用它作为你的 myFunction 而不是你上面的
function myFunction(){
var name = document.getElementById('myname');
<g:remoteFunction controller="test" action="testreport" update="test" params="${[n:name]}"></g:remoteFunction>
}
关于javascript - Remotefunction 上的参数不起作用 grails 2.3.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24651277/