M
M
Max Darkleviathan2020-12-22 15:04:16
PHP
Max Darkleviathan, 2020-12-22 15:04:16

Why doesn't the SSE script work?

There is no output of any information. Naturally, except for the UPD text))) It seems that I am doing everything right. Maybe some libraries on the server are needed?

client side

<h1>UPD</h1>
<div id='console'></div>


<script>

var eventSource = new EventSource('https://test/myphp.php');

eventSource.onmessage = function(e) {
    console.log(e);
};

eventSource.onerror = function(e) {
    console.log(e);
};

</script>


and php

Header('Content-Type: text/Svent-stream');
header('Cache-Control: no-cache');

$data = "server time: ".date("h:i:s", time());

print "data: ".$data. PHP_EOL; echo PHP_EOL;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question