refresh without reloading page php code example
Example 1: php refresh page
header("Refresh:0");
Example 2: php refresh page without reloading
window.addEventListener('load', function()
{
var xhr = null;
getXmlHttpRequestObject = function()
{
if(!xhr)
{
xhr = new XMLHttpRequest();
}
return xhr;
};
updateLiveData = function()
{
var now = new Date();
var url = 'livefeed.txt?' + now.getTime();
xhr = getXmlHttpRequestObject();
xhr.onreadystatechange = evenHandler;
xhr.open("GET", url, true);
xhr.send(null);
};
updateLiveData();
function evenHandler()
{
if(xhr.readyState == 4 && xhr.status == 200)
{
dataDiv = document.getElementById('liveData');
dataDiv.innerHTML = xhr.responseText;
setTimeout(updateLiveData(), 1000);
}
}
});