-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocoms.js
46 lines (39 loc) · 1.12 KB
/
autocoms.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
37
38
39
40
41
42
43
44
45
window.addEventListener('load', function()
{
var x = null;
getXmlHttpRequestObject = function()
{
if(!x)
{
// Create a new XMLHttpRequest object
x = new XMLHttpRequest();
}
return x;
};
updateLiveData = function()
{
var n = new Date();
// Date string is appended as a query with live data
// for not to use the cached version
var url = 'getcoms.php?' + n.getTime();
x = getXmlHttpRequestObject();
x.onreadystatechange = evenHandler;
// asynchronous requests
x.open("GET", url, true);
// Send the request over the network
x.send(null);
};
updateLiveData();
function evenHandler()
{
// Check response is ready or not
if(x.readyState == 4 && x.status == 200)
{
dataDiv = document.getElementById('liveComs');
// Set current data text
dataDiv.innerHTML = x.responseText;
// Update the live data every 1 sec
setTimeout(updateLiveData(), 4000);
}
}
});