Forum Moderators: open
// Javascript / jQuery; I already use jQuery for other things so
// I'm using it here, too, but I used to do it with pure Javascript
setInterval("$('#example').ajax(path)", 15000);
// HTML
<div id="example"></div> var source = new EventSource(path);
source.onmessage = function(event) {
$('#example').html(event.data);
}; if (typeof(EventSource) !== "undefined") {
var source = new EventSource(path + '?src=sse');
source.onmessage = function(event) {
$('#example').html(event.data);
};
}
else
setInterval("$('#example').ajax(path)", 15000);
// Then at the top of "path"
if ($_GET['src'] == 'sse') {
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
}
// and at the bottom of "path"
if ($_GET['src'] == 'sse')
flush(); Failed to load resource: net::ERR_CONNECTION_RESET