简体   繁体   中英

How can I get grails remoteFunction to work?

I have the following code in my gsp

<select onChange="${remoteFunction(action:'superior', controller:'employee', params: '\'name=\' + this.value')}">
    <option>first</option>
    <option>second</option>
</select>

To be specific, this code is in my _form.gsp file. The action in the EmployeeController is as follows:

    def superior() {
    println 'in here'
    println 'these are the params: ' + params
}

It probably seems nonsensical, but my goal here is just to be able to call my remote action and pass the selected value. But I see nothing being printed to the console. If I type the URL directly as follows

app-name/employee/superior

I see my print statements on the output. So what am I missing here? I basically followed how to set this up from the grails documentation (http://grails.org/doc/2.0.x/ref/Tags/remoteFunction.html) and I have the JQuery plugin. If I use a simple javascript function on the onChange event (such as an alert) it works fine. So I'm sure my browser does not have javascript turned off, I've tested this with several browsers actually. I'm pretty sure its something very simple I'm missing. Thanks in advance.

For me this snippet is working perfectly in firefox and chrome. So I guess you have a general javascript error on your page. Check this with firebug. If there is no error, double check the generated code for the onchange tag of your select box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM