Specific javascript can be called if certain events occur, all the events start with the "on" prefix and allow you to give feedback to the user where appropriate, or take other action:
<g:remoteLink action="show"
id="1"
update="success"
onLoading="showProgress()"
onComplete="hideProgress()">Show Book 1</g:remoteLink>
The above code will execute the "showProgress()" function which may show a progress bar or whatever is appropriate. Other events include:
onSuccess
- The javascript function to call if successful
onFailure
- The javascript function to call if the call failed
on_ERROR_CODE
- The javascript function to call to handle specified error codes (eg on404="alert('not found!')")
onUninitialized
- The javascript function to call the a ajax engine failed to initialise
onLoading
- The javascript function to call when the remote function is loading the response
onLoaded
- The javascript function to call when the remote function is completed loading the response
onComplete
- The javascript function to call when the remote function is complete, including any updates
If you need a reference to the
XmlHttpRequest
object you can use the implicit event parameter
e
to obtain it:
<g:javascript>
function fireMe(e) {
alert("XmlHttpRequest = " + e)
}
}
</g:javascript>
<g:remoteLink action="example"
update="success"
onSuccess="fireMe(e)">Ajax Link</g:remoteLink>