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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now