forked from ripasaha/session-timeout-alert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.js
36 lines (35 loc) · 806 Bytes
/
ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
window.onload = init;
var interval;
function init()
{
interval = setInterval(trackLogin,1000);
}
function trackLogin()
{
var xmlReq = false;
try {
xmlReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlReq = false;
}
}
if (!xmlReq && typeof XMLHttpRequest != 'undefined') {
xmlReq = new XMLHttpRequest();
}
xmlReq.open('get', 'check.php', true);
xmlReq.setRequestHeader("Connection", "close");
xmlReq.send(null);
xmlReq.onreadystatechange = function(){
if(xmlReq.readyState == 4 && xmlReq.status==200) {
if(xmlReq.responseText == 1)
{
clearInterval(interval);
alert('You have been logged out.You will now be redirected to home page.');
document.location.href = "index.html";
}
}
}
}