//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'); }