session expire during ajax call issue


I noticed some not very user friendly situation during an ajax execution. Here is the situation:

I have setup the loginUrl to be my index page so when login session expires the user gets redirected to my index page.

I click on a button which triggers an ajax call and updates a specific div of the webpage. What happens though is after the ajax is been triggered the application has decided that the login session has expired and the result is my whole index webpage gets loaded into the ajax update section. Has anybody else seen that? It looks very unprofessional and ugly. I couldn’t find related posts so I raised this one. Any advice on how to deal with this situation is welcome.



Yeah, I also have this and it was added to my TODO list. Haven’t thought about it since, perhaps one solution might be to check for some expected return value in the ‘success’ handler.


Hi all!!

I have a dirty (but working) solution, that needs to be a bit cleaned. Look at this:


	 * Displays the login page


	public function actionLogin()



		if (Yii::app()->request->urlReferrer!== Yii::app()->request->hostInfo.CHtml::normalizeUrl(array('/site/login')))



			echo '

				<script type="text/javascript">







	//the usual login action

Is a modified version of the login page. It checks if the previous page was login too, if is it will as usual shows the login form and login if succesfully.

If not it send a javascript that redirect to the login page.

This Javascript works even in an ajax request, so if the session expire during an ajax call, the user will be redirected to the login page, instead of this bad behaviour.

The problem is that the user will be redirected 2 times:

  • the first time the ref is the page from wich is the request

  • the second the ref is corrected, so the login is displayed correctly

that is the dirty point: if is possible to find any way for understand if the request from wich we were redirect was an ajax request, we can put this condition in the "if" and avoid to redirect 2 times

NB: Yii::app()->request()->isAjaxRequest don’t works, don’t know why.

Anyone of you has an idea?