Primefaces:所有Ajax请求默认的onComplete方法方法、Primefaces、Ajax、onComplete

由网友(旧街里的酒)分享简介:我想对所有Ajax请求配置的onComplete方法,这样我可以处理会话超时。 I am trying to configure an oncomplete method for all ajax requests so that I can handle session timeout. 我尝试添加下面的脚本,但...

我想对所有Ajax请求配置的onComplete方法,这样我可以处理会话超时。

I am trying to configure an oncomplete method for all ajax requests so that I can handle session timeout.

我尝试添加下面的脚本,但它并没有以同样的方式工作作为设置的onComplete属性号码:AJAX元素。这一个Ajax请求时每次都不会执行。

I tried adding the following script but it didn't work the same way as setting oncomplete property for p:ajax element. It wouldn't execute each time an Ajax request is made.

$.ajaxSetup({method: post,
    complete: function(xhr, status, args){
        var xdoc = xhr.responseXML;
        if(xdoc == null){
            return;
        }
        errorNodes = xdoc.getElementsByTagName('error-name');

        if (errorNodes.length == 0) {
            return;
        }

        errorName = errorNodes[0].childNodes[0].nodeValue;
        errorValueNode = xmlDoc.getElementsByTagName('error-message');
        errorValue = errorValueNode[0].childNodes[0].nodeValue;

        alert(errorValue);
        document.location.href='${pageContext.request.contextPath}/login/login.jsf';
    }
});

任何帮助将AP preciated

Any help would be appreciated

推荐答案

我设法通过包装Primefaces AjaxUtils方法来实现这一点。

I managed to implement this by wrapping Primefaces AjaxUtils method.

var originalPrimeFacesAjaxUtilsSend = PrimeFaces.ajax.AjaxUtils.send;

   PrimeFaces.ajax.AjaxUtils.send = function(cfg) {
      if (!cfg.oncomplete) {
         // register default handler
         cfg.oncomplete = oncompleteDefaultHandler;
      }
      originalPrimeFacesAjaxUtilsSend.apply(this, arguments);
   };
阅读全文

相关推荐

最新文章