Jump to content

server sent events

Recommended Posts


Am trying to execute basic example from w3schools, but am only getting 

"Getting server updates " print and nothing else.

I have kept my two files.index.html and "demo_sse.php" in same folder and trying to load html file.

demo_sse.php :

header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$time = date('r');
echo "data: The server time is: {$time}\n\n";



<!DOCTYPE html>

<h1>Getting server updates</h1>
<div id="result"></div>

if(typeof(EventSource) !== "undefined") {
    var source = new EventSource("demo_sse.php");
    source.onmessage = function(event) {
        document.getElementById("result").innerHTML += event.data + "<br>";
} else {
    document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";



Please suggest any mistake am doing here


Thanks and Regards

Rizwan Syed

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...