Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

javascript - Server Sent Events error despite http 200

Hello I have next two files: testsse.html

<!DOCTYPE html>
<h1>Test of server sent events</h1>
<script>
    var eventSource = new EventSource("sse.php");
    eventSource.onmessage = function(event) {
    console.log("It works");
};
eventSource.onerror = function(error) {
console.error("eventSource failed: ", error);
};
</script>

And sse.php

<?php
header("Content-Type: text/event-stream

");
header('Cache-Control: no-cache');
echo "ssetest

";
flush();
?>

So in console there are a lot of errors, and in the network tab a lot of pings, here the screenshots: enter image description here enter image description here

MDN says if response from server is 200, means all is ok, but in network tab you can clearly see there are response code 200, but still erorrs at console that are very big. Code is very small and easy so I dont even know what is causing problem. Also path to sse.php is correct (I hide it from screenshots with black boxes)

question from:https://stackoverflow.com/questions/66047672/server-sent-events-error-despite-http-200

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...