将Javascript变量传递给grails RemoteFunction

dan*_*ger 5 javascript parameters grails dom

可能重复:
作为javascript函数的结果,在g:remoteLink中传递参数

我试图调用一个onclick为按钮触发的remoteFunction调用,但是click不会调用该函数.我已经使用警报启动测试了onlick命令并调用了该函数.这是我的代码.

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

function exportList(){

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


}
Run Code Online (Sandbox Code Playgroud)

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

Kel*_*lly 3

JoeCortopassi 是正确的 - 你不能${remoteFunction...}直接在 javascript 中使用 grails 构造。我已经使用 Jquery 完成了此操作,如下所示:

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