JSF2.0 - 处理错误的Ajax和Primefaces 3.0来电 [英] JSF2.0 - Handling erroneous Ajax calls with Primefaces 3.0
问题描述
我有一个的commandButton
在我.xhtml页面:
I have a commandButton
in my .xhtml page:
<p:commandButton action="#{someone.doSomething()}"
ajax="true"
onerror="errorDialog.show();">
</p:commandButton>
它只是调用Ajax。如何检测,如网络连接问题(客户端/浏览器),超时,会话超时,服务器端的异常,死机等在Ajax调用中,以显示一个信息消息给用户的情况呢?
It's simply making an Ajax call. How can I detect situations such as internet connection problem (of the client/browser), timeout, session-timeout, server-side exceptions, crashes etc in the middle of an Ajax call so as to show an informative message to the user?
难道 P的
处理所有这些的?如果不是,那么是什么? :)
什么是默认的超时顺便说一句?的onerror
属性:AJAX
Does the onerror
attribute of p:ajax
handle all of those? If not, then what? :)
What's the default timeout btw?
任何帮助AP preciated,谢谢。
Any help appreciated, thanks.
推荐答案
onError的调用该函数:
onError的(XHR,状态异常) - JavaScript回调时AJAX请求失败处理。有三个参数,xmlhtt prequest,状态字符串和异常,如果任何异常。
这信息是从文档。 XHR - 实际上是一个请求。所以可以faound请求的状态和很多其他的信息。
onerror calls this function:
onerror(xhr, status, exception) - Javascript callback to process when ajax request fails. Takes three arguments, xmlhttprequest, status string and exception thrown if any.
This info is from documentation. xhr - is actually a request. So there can be faound request status and a lot of other info.
<p:commandButton action="#{someone.doSomething()}"
ajax="true"
onerror="console.debug(xhr)">
</p:commandButton>
试试这个code镀铬或萤火虫。它会显示XHR对象
try this code in chrome or in firebug. It will show xhr object
一睹为 HTTP://primefaces.google$c$c。 COM /文件/ primefaces_users_guide_3_0.pdf 部分7.2 AJAX API
Get a look into http://primefaces.googlecode.com/files/primefaces_users_guide_3_0.pdf section 7.2 Ajax API
这篇关于JSF2.0 - 处理错误的Ajax和Primefaces 3.0来电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!