1

I have a Groovy/Grails project with a view that has some data rendered to it from its controller, say the controller is called MyController and the data I want to render is called ${myData}. The relevant part of my view looks like this:

<head>
    $('#refreshData').click(function(){
        //here I want to run the method in my controller and update the value of myData
    });
    ...
</head>    

<body>
    ...    
    <input type="text" id="inputData" />
    <button id="refreshData">Submit</button>
    ...
</body>

My controller has an action that receives an argument of type String (it's supposed to receive it from the input form)

def updateData(String input) {
    //updating input
    [myData: return_value]
}

I want to call the action updateData from my jquery function either by having a local js variable assigned with the return value of that function or by having a variable rendered to my view and accessing it. I tried calling

var newData = ${
    remoteFunction(
        controller: 'my', 
        action: 'updateData', 
        params =[string_from_form]
    )};

but I am getting the error groovy.lang.MissingMethodException with a message of the form

No signature of method <> is applicable for values (java.util.LinkedHashMap, java.util.ArrayList) values: [[controller:my...

Can somebody please tell me how to call the controller method with my parameter from that jQuery function?

2 Answers 2

2

Looks like you might have a bug in the params section of your code. Try:

var newData = ${remoteFunction(controller: 'my', action: 'updateData', params: '[string_from_form]')};
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That was indeed the problem, but I resorted to $.post("${createLink(controller:..., action:...), param1:..., function(data)={...}}"). Seems more js like.
0

You want params: instead of params =.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.