【问题标题】:How to show error message when my server is down / not available while making JQuery request?如何在发出 JQuery 请求时我的服务器关闭/不可用时显示错误消息?
【发布时间】:2013-04-27 12:09:56
【问题描述】:

我有一个类似这样的代码;

<a4j:commandLink   
actionListener="#{controller.validate}"  
onclick="showFadeLoadingImg();"  
oncomplete="confirmOperation();}"  
value="#{actionItem.actionDisplayName}"  
reRender="text1,text2">  
</a4j:commandLink>  

在这里,当我的服务器关闭时,我的 oncomplete 事件具有 jscript 函数 confirmOperation(),该函数将被执行,并显示该函数的不需要的输出。但是,我最终想要的是,当我单击按钮时,我想检查我是否能够连接到服务器,如果不能,我必须显示一些错误消息,例如 'Unable to reach server' 。你能给我实现这个的代码示例吗?

【问题讨论】:

  • 你的意思是一个 Ajax 请求?
  • 你究竟为什么要标记 jQuery? RichFaces 3.x 并没有在幕后使用 jQuery。只有 RichFaces 4.x 可以。 reRender 属性的存在意味着 3.x(在 4.x 中已重命名为 render)。 RichFaces 3.x 在幕后使用 Prototype.js。到目前为止发布的 JSF 代码似乎没有在任何地方使用 jQuery。

标签: javascript jquery jsf richfaces ajax4jsf


【解决方案1】:

创建一个 Ajax 请求,例如-

var jqAjax =   $.ajax({
                                           url:  'server URL',
                                           type: "GET/POST",
                                           dataType: "TYPE" , 
                                           });

然后,实施

jqAjax.fail(function(jqXHR, textStatus, errorThrown){
  //Check the textStatus
});

检查textStatus,获取值 - 0, 404, 500, timeout, abort, parsererror

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 2021-12-23
    • 1970-01-01
    • 2011-02-26
    • 2014-02-08
    • 2013-02-03
    相关资源
    最近更新 更多