Yii Framework Forum: session expire during ajax call issue - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

session expire during ajax call issue 1.1 Rate Topic: -----

#1 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 752
  • Joined: 02-February 09

Posted 03 June 2010 - 05:37 AM

Hi,

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.

Thanks,
bettor
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 03 June 2010 - 06:06 AM

View Postbettor, on 03 June 2010 - 05:37 AM, said:

Hi,

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.

Thanks,
bettor


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.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 03 June 2010 - 07:54 AM

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')))
		{
			$url=CHtml::normalizeUrl(array('/site/login'));
			echo '
				<script type="text/javascript">
				/*<![CDATA[*/
				 document.location.href="'.$url.'";
				/*]]>*/
				</script>';
				return;
		}

	//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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users