problem with ajax timeout

Hi

I am facing problem ajax session time out

after 2 to 3 hours when i click on ajax link that is next in cgrid view, grid will not display anything but the upper part will be display

please help me

thanks

I guess you mean that the problem is that you leave your browser open for X hours, and when you come back the ajax-call will time out since the user session is lost?

If so, doing periodical fetches to a simple “keep-alive” script on the server would solve your problem. If that’s not viable you can extend the session timeout config for PHP.

A different approach would be to catch the ajax-error and redirect to login or similar.

hi sir

can u please tell how can do the ,extend the session timeout config for PHP

thank you reply

Hi,

I am not sure but I think I saw that with 1.1.9 we have some form of solution for this:

I know that this does not solve your problem directly but decided to post this for consistency and this would help with eirikhm’s second solution. I don’t know yet how this is used in real application as I just discovered it myself. If anybody has tested it and can post an example that would be great

Hi ,

i have a problem, Once the session expired, a page with AJAX actions will still be displayed normally. But obviously, any AJAX request will be denied, which is confusing. I would like to find a system to inform the user that his session has expired and apply to all pages in the back office.

thanks for your attention

Hugo

You may want to check this:

A New And Improved jQuery Idle Timeout Plugin

Thanks alot, i will check it out

I was having similar issues handling ajax interactions when the session had timed out. The way I resolved the confusion was by having the controller return an error message when an unauthorized call is made to the ajax action (as would happen with a session timeout), detecting this error message in my javascript ajax function, and then redirecting to the homepage / login screen.

In my controller:




public function accessRules()

{

	return array('allow',

		'actions' => array('actionIndex', 'ajaxAction', 'ajaxAnotherAction'), 

		'users' => array('@'),

	),

	array('deny',  // Return error code for ajax actions

		'actions' => array('ajaxAction', 'ajaxAnotherAction'),

		'users' => array('*'),

		'deniedCallback' => function() { echo 'unauthorized access'; }

	),

	array('deny',  // Redirect to index for all other actions

		'users' => array('*'),

		'deniedCallback' => function() { Yii::app()->controller->redirect(array ('/site/index')); }

	),

}



Then, in my javascript:




$.ajax({

	type: "POST",

	url: "controller/action",

	success: function(response){

		// If user denied access (i.e. session timeout), redirect to index

		if (response == 'unauthorized access') {

			alert('Your session has expired.  Please login again.');

			window.location = "/";

			return false;

		}

		// Continue with normal ajax response actions

		$('#newcontent').html(response);

	}

});



Final note: I think you need Yii v1.1.11 or later to use callback in accessRules().