Welcome! Log In Create A New Profile

Advanced

server side events

Posted by Allard 
server side events
January 03, 2020 09:04AM
Hello ,

I saw something in the help on this but no code what so ever. This is a feature of webdevelopment since 2006!!

Ok Has anyone ever used this with webdev?

I Need to add some servercode in phpo it would be like this

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

$time = date('r');
echo "data: The server time is: {$time}\n\n";
flush();

The javascript to get the page changes would be like this

var source = new EventSource("PAGE_Onderhoiud.php");
source.onmessage = function(event) {
document.getElementById("result").innerHTML += event.data + "<br>";


There is no framework or anything used . This is it. SSE is great . A lot less overhead then witch websockets as that is a whole different protocol

Adding the phpo and the javascript does not work!! ( at least if I try it ) . The code runs without webdev like a charm

Regards
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: