作者:危亚丽 | 来源:互联网 | 2013-06-09 10:34
问题
用户在较长时间内没有动作,php回话已经超时,回话过期后又有一个ajax请求但是程序并没有任何反应,例如在gridview中,gridview的内容完全消失。
正确的行为
显示登录页面,登录后再重定向回来。
解决方法
在配置文件中设置loginRequiredAjaxResponse:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
...
'components'=>array(
'user'=>array(
...
'loginRequiredAjaxResponse'=>'YII_LOGIN_REQUIRED',
...
),
...
In your viewortemplate
if(Yii::app()->components['user']->loginRequiredAjaxResponse){
Yii::app()->clientScript->registerScript('ajaxLoginRequired', '
jQuery("body").ajaxComplete(
function(event, request, options) {
if(request.respOnseText=="'.Yii::app()->components['user']->loginRequiredAjaxResponse.'") {
window.location.href = options.url;
}
}
);
');
}
?>
|
注意:
以上代码在options.url为可用页面的url是测试通过,如果不是这种情况或者你只是想显示登录页面请替换:
1
|
window.location.href = options.url;
|
为
1
|
window.location.href ="'.Yii::app()->createUrl('/site/login').'";
|