How to set onSuccess event listener for Grails

Grails inherently supports ajax function, such as remoteFunction, remoteLink, etc.

But do you know how to set onSuccess event listener appropriately?

Let me tell you :)

<input type=”text” id=”name” name=”name” value=”"/>
<input type=”button” name=”checkbizname” value=”Chek whether this name already exists” onclick=”${remoteFunction(controller:’mycontroller’,action:’isNameExists’,onSuccess:’popwin(o)’, params:’\'name=\’ + document.getElementById(\’name\’).value’)}”/>

In the above code, when ajax request is handled and get response from server, onSuccess event listener will be invoked.

Note:

  1. popwin(o) should contain argument ‘o’, as ‘o’ is defined in the code generated by this GSP. You can find this argument via firebug. {success: function(o){popwin(o);}, failure: function(o){}}
  2. Another important thing is, you should define this function popwin(o) in head section in GSP. It seems a bug that funtions defined between head and body will not be invoked at all.
By javafuns on May 21, 2009 at 22:11 · Views: 2,082 · Permalink
Categorized in: Scripts · Tagged with: , , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply


  • Highest Rated

  • My PicasaPhotos

    IMG_0649.JPG

    IMG_0620.JPG

    IMG_0574.JPG

  • RSS My del.icio.us

  • My RSS