Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Javascript Variable into grails RemoteFunction [duplicate]

Possible Duplicate:
pass parameter in g:remoteLink as result of javascript function

I am trying to call a remoteFunction call that is triggered by an onclick for a button, but the click does not call the function. I have tested the onlick command with an alert startment and the function is called. here is my code.

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

function exportList(){

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


}

When I take out the parameter and the var profile, the function is STILL not called... My controller and action are properly named so I do not know why I am having this error. Thanks in advance if you can help!

like image 721
daniel langer Avatar asked Jun 14 '12 21:06

daniel langer


2 Answers

JoeCortopassi is correct - you can't just use the grails construct of ${remoteFunction...} directly in javascript. I've done this using Jquery like this:

function exportList() {
    var profileToUse = document.getElementById('dropdown').value
    jQuery.ajax({
        url: "/youApp/profile/export",
        type: "POST",
        data: {profile: profileToUse}
    });
}
like image 137
Kelly Avatar answered Nov 08 '22 03:11

Kelly


I don't know what this is supposed to do, but it looks poorly formed

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

are you sure you want to say var{remoteFunction()}? Cause $ is just a variable. Makes even less sense if you are using jQuery. Also, what you are passing remoteFunction() looks like it was supposed to be object, but isn't wrapped in {}

like image 20
JoeCortopassi Avatar answered Nov 08 '22 04:11

JoeCortopassi