W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1 id="myH1"></h1> <div id="myDIV"></div> <p><b>注释:</b>Internet Explorer 不支持 Server-Sent 事件。</p> <script> if(typeof(EventSource) !== "undefined") { var source = new EventSource("/html/demo_sse.php"); source.onopen = function() { document.getElementById("myH1").innerHTML = "Getting server updates"; }; source.onmessage = function(event) { document.getElementById("myDIV").innerHTML += event.data + "<br>"; }; } else { document.getElementById("myDIV").innerHTML = "Sorry, your browser does not support server-sent events..."; } </script> </body> </html>