Adaptive Javascript in Grails With JQuery

This article in now outdated

Adaptive Javascript in Grails with JQuery

The Grails framework uses a technology called Adaptive Javascript that enables easy development of Ajax requests. Developers can code Ajax enabled links and forms using a set of standard grails tags such as <g:remoteLink> or <g:remoteForm> in Groovy server pages and Grails internally generates the required javascript code to send the Ajax requests to servers based on the javascript library configured to work with Grails. Grails uses the Prototype library by default and the 1.4 version promises to move to jQuery as the standard. The code written is non-obtrusive, i.e. if Javascript is not enabled the forms or links will work as normal html forms or links respectively.

There is one caveat to using this method though. There are cases where the developer is required to call a custom function based on the result of an Ajax request. The standard documentation states the method signature to be used for such Ajax events of the form onSucess=’fireMe(e)’”

This is typical to the Prototype library and does not work with jQuery. When using jQuery, the browser will complain about unknown event ‘e’. The way to get this working is to make sure the signature used follows the accepted jQuery standard which is “onSucess=’fireMe(data, textStatus)’” where data is the response data of the Ajax call and textStatus is the HTTP status of the Ajax request in string form

Update Nov 2011: As of Grails 2.0, the default javascript library is JQuery and the Prototype way of adaptive javascript no longer works. Please refer the Grails framework documentation.