Events dispatched by the server Stop starting with a new parameter

Please, help.

I am using Server Sent Events to dynamically update a website based on the data stored in the database.

Now I want to pass the new parameter ('abc.php /? LastID = xxx') back to the PHP script based on the data received in the previous message.

As I understand it, I can use event.close to stop the current thread, but it's hard for them to figure out how to use the same 'EventListener' for every new EventSource where the URL is dynamically generated.

Can someone point me in the right direction?

Thanks,

+4
source share
1 answer

Well spent some time understanding Javascript better.

 var source = new EventSource("xyz.php?last=0"); source.addEventListener('message', onMessageHandler,false); function onMessageHandler(event) { console.log(event.data);//just for debug purposes event.target.close(); //close current stream. var last = "1234"; // loaded from event.data in my solution. var sourceNew = new EventSource("xyz.php?last=" + last); // start another sourceNew.addEventListener('message', onMessageHandler, false); //event } 

and I seem to have solved the problem I had.

That

+6
source

All Articles