Redirect to new page on session expire, in Zend_Auth
I'm using zend 1.11 framework with doctrine . I'm sending below ajax request to populate dropdown list & etc... But once session expired i'm redirecting to login page in every actions of controllers. So i'm getting whole html page as response if session got expired. How to do that in javascript (how can i find out whole html response or not)开发者_C百科 . I'm using Zend_Auth for session management.
function loadzone(value)
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("district_span").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/main/zonechange?zc="+value,true);
xmlhttp.send();
}
Well to my understanding: A user is logged in and opens some form. You do AJAX-Checkups to see if user is still logged in. If user was idle for too long the session will expire. In that case you want to redirect the user?
If is is like i think you can just give the user a bad callback. This can be done like this:
$this->_response->setHttpResponseCode(401); //401 = unauthorized
If you do so, you can just extend your JS Functionality to catch that code
if (xmlhttp.readyState==4 && xmlhttp.status==401) {
//do the redirect
}
Is this what you're asking for or did i misinterpret your question? :) Additional Information regarding response codes can be found here: http://de.wikipedia.org/wiki/HTTP-Statuscode
精彩评论