![]() |
|
Snippets |
|
This snippet is usefull to handle a session timeout in an ajax request.
It is very bad to have the login page filling the update div zone...
The idea came from a post in the forum (thanks a lot RoVeRT !)
The method is :
The security module redirect the request to the login action.
The login action send a 401 http error code if it detects an ajax request.
The ajax helper handle the 401 error with a javascript function which display a popup and redirect to the full login page.
For that purpose, we will add a little code in the ajax helper and in the login action.
1 - We handle the 401 error code in the ajax helper and enable javascript execution for the popup :
401 => "if ( confirm('Your not logged anymore... Ok to go to the login page.')) {document.location='/';}",
2 - We add this code at the beginning of the login action :
// if the request is an ajax request... if ($this->getRequest()->isXmlHttpRequest()) { // response to the ajax request : code http 401 (access unauthorized) $this->getResponse()->setStatusCode(401); }
Thanks for the comments !