open 예제
<h1 id="hz"></h1> <div id="s_time"></div> <script> if(typeof(EventSource) !== "undefined") { var source = new EventSource("/server_time.php"); source.onopen = function() { document.getElementById("hz").innerHTML = "홈짱닷컴 (Homzzang.com) 서버갱신시간"; }; source.onmessage = function(event) { document.getElementById("s_time").innerHTML += event.data + "<br>"; }; } else { document.getElementById("s_time").innerHTML = "서버전송이벤트 지원않는 브라우저는 개나 줘버려."; } </script> /server_time.php 소스 <?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); $time = date('r'); echo "data: 서버시간: {$time}\n\n"; flush(); ?>
<h1 id="hz"></h1>
<div id="s_time"></div>
<script>
if(typeof(EventSource) !== "undefined") {
var source = new EventSource("/server_time.php");
source.onopen = function() {
document.getElementById("hz").innerHTML = "홈짱닷컴 (Homzzang.com) 서버갱신시간";
};
source.onmessage = function(event) {
document.getElementById("s_time").innerHTML += event.data + "<br>";
} else {
document.getElementById("s_time").innerHTML = "서버전송이벤트 지원않는 브라우저는 개나 줘버려.";
}
</script>
/server_time.php 소스
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$time = date('r');
echo "data: 서버시간: {$time}\n\n";
flush();
?>