[英]How to handle non ajax response after partial ajax request?
I make a partial ajax request from a page and if I don't get a partial ajax response as response or if the partial ajax response is malformed I cannot find a way to handle it. 我从页面发出部分ajax请求,如果没有得到部分ajax响应作为响应,或者如果部分ajax响应格式不正确,则无法找到处理方法。 Client side just make no actions in such cases and just stays cool.
客户端只会在这种情况下不采取任何措施,并且保持冷静。
It happens when session is expired and server returns non ajax response (without <partial-response>
tag) instead of ajax response or when an exception is trown so <partial-response>
becomes malformed and has no ending tag. 当会话过期并且服务器返回非ajax响应(没有
<partial-response>
标记)而不是ajax响应时,或者发生异常,因此<partial-response>
变得格式错误并且没有结束标记时,会发生这种情况。
Any idea? 任何想法?
I tried to override PrimeFaces.ajax.Response.handle
function on the client side but it's not called in such cases (because non ajax response is returned). 我试图覆盖客户端的
PrimeFaces.ajax.Response.handle
函数,但是在这种情况下不会调用它(因为返回了非ajax响应)。
And solution is to put this java code in login.jsp page to identify ajax requests 解决方案是将此Java代码放入login.jsp页面中以标识ajax请求
<%
boolean ajax = "XMLHttpRequest".equals( request.getHeader( "X-Requested-With" ) );
if ( ajax ) {
// Authentication Timeout
response.setStatus( 419 );
}
%>
and jQuery on client side (eg in some template) 和客户端上的jQuery(例如,在某些模板中)
<script>
$.ajaxSetup({
statusCode: {
419: function() {
location.reload();
}
}
})
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.