我的.xhtml页面中有一个commandButton
:
<p:commandButton action="#{someone.doSomething()}"
ajax="true"
onerror="errorDialog.show();">
</p:commandButton>
它只是在进行Ajax调用。如何在Ajax调用过程中检测互联网连接问题(客户端/浏览器),超时,会话超时,服务器端异常,崩溃等情况,以便向用户显示信息性消息?
onerror
的{{1}}属性是否处理了所有这些属性?如果没有,那又怎样? :)
什么是默认超时btw?
感谢任何帮助,谢谢。
答案 0 :(得分:2)
onerror调用此函数:
onerror(xhr,status,exception) - 当ajax请求失败时要处理的Javascript回调。采用三个参数,xmlhttprequest,状态字符串和抛出的异常(如果有的话)。
此信息来自文档。 xhr - 实际上是一个请求。因此,可以找到请求状态和许多其他信息。
<p:commandButton action="#{someone.doSomething()}"
ajax="true"
onerror="console.debug(xhr)">
</p:commandButton>
在chrome或firebug中尝试此代码。它将显示xhr对象
查看http://primefaces.googlecode.com/files/primefaces_users_guide_3_0.pdf第7.2节Ajax API