我的 .xhtml 页面中有一个 commandButton
:
<p:commandButton action="#{someone.doSomething()}"
ajax="true"
onerror="errorDialog.show();">
</p:commandButton>
它只是进行 Ajax 调用。如何在 Ajax 调用过程中检测互联网连接问题(客户端/浏览器)、超时、 session 超时、服务器端异常、崩溃等情况,以便向用户显示信息性消息?
p:ajax
的 onerror
属性是否处理所有这些?如果不是,那又怎样? :)
顺便说一句,默认超时是多少?
感谢任何帮助,谢谢。
最佳答案
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
关于java - JSF2.0 - 使用 Primefaces 3.0 处理错误的 Ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8804020/