【问题标题】:Pass Javascript Variable into grails RemoteFunction [duplicate]将 Javascript 变量传递到 grails RemoteFunction [重复]
【发布时间】:2012-06-17 23:15:15
【问题描述】:

可能重复:
pass parameter in g:remoteLink as result of javascript function

我正在尝试调用由按钮的 onclick 触发的 remoteFunction 调用,但单击不会调用该函数。我已经使用警报启动测试了 onlick 命令并调用了该函数。这是我的代码。

<input type="button" onclick="exportList()" value= "Export"/>

function exportList(){

            var profile= document.getElementById('dropdown').value
            ${remoteFunction(controller: 'profile' , action:'export', params: "'profile=' + profile")}  


}

当我取出参数和 var 配置文件时,仍然没有调用该函数...我的控制器和操作已正确命名,所以我不知道为什么会出现此错误。如果您能提供帮助,请提前致谢!

【问题讨论】:

标签: javascript dom grails parameters


【解决方案1】:

JoeCortopassi 是正确的 - 您不能直接在 javascript 中使用 ${remoteFunction...} 的 grails 构造。我已经像这样使用 Jquery 完成了这项工作:

function exportList() {
    var profileToUse = document.getElementById('dropdown').value
    jQuery.ajax({
        url: "/youApp/profile/export",
        type: "POST",
        data: {profile: profileToUse}
    });
}

【讨论】:

  • 这是正确的答案。我只是不熟悉 Grails,谢谢@Kelly
【解决方案2】:

我不知道这是做什么的,但它看起来很糟糕

${remoteFunction(controller: 'profile' , action:'export', params: "'profile=' + profile")} 

你确定要说var{remoteFunction()}吗?因为$ 只是一个变量。如果您使用的是 jQuery,那就更没有意义了。此外,您传递的 remoteFunction() 看起来应该是对象,但没有包含在 {}

【讨论】:

  • 为另一个想法编辑@daniellanger
  • 我不明白你在提议什么
  • 试图说 ${remoteFunction(... 部分看起来不像正确的 javascript
猜你喜欢
  • 2016-03-27
  • 1970-01-01
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
  • 2014-09-09
  • 2014-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多