Files
Metadata_PHP/metadata/dbms/session.js
2020-02-27 00:28:43 +06:00

58 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//AJAX запросы для проверки сесии
function CheckSession(path)
{
this.processReqChange=function(req,url)
{
if(req.readyState === 4 || typeof(req.readyState) === 'undefined')
{
if(req.status === 200 || typeof(req.status) === 'undefined')
{
if(url.indexOf('fn=0')>=0)
{
this.ses_name=req.responseText;
this.sendReq('?fn=1');
}else
if(url.indexOf('fn=1')>=0)
{
this.ses_id=req.responseText;
this.run();
}else
if(url.indexOf('fn=2')>=0)
{
if(parseInt(req.responseText)<0)
{
clearTimeout(this.timer);
//alert('Ваша сессия завершилась!');
//location.reload();
alert2('Ваша сессия завершилась! При нажатии на “OK” страница перезагрузится, а при нажатии на “X“ закроется сообщение.').onclick=function(){ location.reload(); };
}
}
}
}
};
//Отправить запрос на сервер
this.sendReq=function(prm)
{
var url=this.path+prm; //'http://'+document.domain+this.path+prm
var req = new window.XMLHttpRequest;
req.onreadystatechange=function(thiz,req,url){ return function(){ thiz.processReqChange(req,url) } }(this,req,url);
req.open("GET", url, true);
req.send(null);
};
//Запрос состояния сессии через заданный интервал
this.run=function()
{
this.sendReq('?fn=2&'+this.ses_name+'='+this.ses_id);
this.timer=setTimeout(function(thiz){ return function(){ thiz.run(); }}(this), 60000);
};
this.path=path; //URL файла session.php
this.ses_name=''; //Наименование сесии
this.ses_id=''; //Идентификатор сесии
this.timer=0; //Идентификатор таймера
this.sendReq('?fn=0');
}