Hello I have a javascript code that listens to a PHP code via Server-Sent Events, it is working well the response is sent from the server trough a loop and when the loop end
Hi I've added extra to (hopefully fix this) You have to pass from the server a message to close the connection. Otherwise when the execution finishes the browser will start with a new connection
air code
JS :
var sse=new EventSource("data.php");
sse.onmessage=function(event){
if ('END-OF-STREAM' == event.data) {
sse.close(); // stop retry
}
document.getElementById("map").innerHTML+=event.data;
};
PHP: