//-------------------- live.php // First detect browser-type, as some browsers are picky. if (strstr($_SERVER['HTTP_USER_AGENT'], 'Safari')) { // Safari required at least 1024 bytes before displaying echo str_pad('',1024); $browser = "safari"; }
// Begin our loop that only aborts if the client disconnects while(!connection_aborted()) { $i+=3; // Safari requires a padding of 8 characters echo ($browser = "safari" ? str_pad($i, 8) : $i); // Output current data with flush() flush(); // Sleep for 3 seconds sleep(3); } ?>
//-------------------- nStream.js // set connection as a global variable var connection = null
function nStream(url) { setInterval(nParse, 1000); if (!/*@cc_on!@*/false) { connection = new XMLHttpRequest(); } else { connection = new ActiveXObject("Microsoft.XMLHTTP"); } connection.open("GET", url, true); connection.onreadystatechange = function() { if (connection.readyState == 4) { alert('connection closed.'); } } connection.send(null); }
oldResponse = null; function nParse() { var Response = connection.responseText; if (Response != oldResponse) { document.getElementById('change').innerHTML = Response; } oldResponse = Response; }
Post a Comment