Grails 1.1 GSP 用Prototype实现Ajax - Ajax事件

某些事件的发生会调用特定的javascript。所有以"on"开头的事件,在适当的时候允许你反馈信息给用户,或采取其他行为:<g:remoteLink action="show" id="1" update="success" onLoading="showProgress()" onComplete="hideProgress()"> Show Book 1 </g:remoteLink>上述代码将执行"showProgress()"函数来显示一个进度条或者其他适当的展示,其他的事件
还包括 :
• onSuccess - 成功时调用的javascript函数

• onFailure - 失败时调用的javascript函数

• on_ERROR_CODE - 处理指定的错误代码时调用的javascript函数 (例如on404=“alert(‘not found!’)”)

• onUninitialized - 一个ajax引擎初始化失败时调用的javascript函数

• onLoading - 当远程函数加载响应时调用的javascript函数

• onLoaded - 当远程函数加载完响应时调用的javascript函数

• onComplete - 当远程函数完成(包括任何更新)时调用的javascript函数

假如你需要引用XmlHttpRequest对象,你可以使用隐式的event参数e获取它 :<g:javascript> function fireMe(e) { alert("XmlHttpRequest = " + e) } } </g:javascript> <g:remoteLink action="example" update="success" onSuccess="fireMe(e)">Ajax Link</g:remoteLink>