1//refreshes your current page
2header("Refresh:0");
3
4//refreshes your current page after 5 seconds
5header("Refresh:5");
6
7//If you need to redirect it to another page
8header("Refresh:0; url=page2.php");
1//Refreshes your current page
2header("Refresh:0");
3header("Refresh:2"); // Refreshes after 2 seconds
4
5//If you need to redirect it to another page
6header("Refresh:0; url=page2.php");
1window.addEventListener('load', function()
2{
3 var xhr = null;
4
5 getXmlHttpRequestObject = function()
6 {
7 if(!xhr)
8 {
9 // Create a new XMLHttpRequest object
10 xhr = new XMLHttpRequest();
11 }
12 return xhr;
13 };
14
15 updateLiveData = function()
16 {
17 var now = new Date();
18 // Date string is appended as a query with live data
19 // for not to use the cached version
20 var url = 'livefeed.txt?' + now.getTime();
21 xhr = getXmlHttpRequestObject();
22 xhr.onreadystatechange = evenHandler;
23 // asynchronous requests
24 xhr.open("GET", url, true);
25 // Send the request over the network
26 xhr.send(null);
27 };
28
29 updateLiveData();
30
31 function evenHandler()
32 {
33 // Check response is ready or not
34 if(xhr.readyState == 4 && xhr.status == 200)
35 {
36 dataDiv = document.getElementById('liveData');
37 // Set current data text
38 dataDiv.innerHTML = xhr.responseText;
39 // Update the live data every 1 sec
40 setTimeout(updateLiveData(), 1000);
41 }
42 }
43});
44