Server Sent Events Stop Start with new parameter

前端 未结 1 1496
你的背包
你的背包 2021-01-14 00:40

please help.

I\'m using Server Sent Events to dynamically update a website based on data stored in a database.

I now wish to pass a new parameter (\'abc.php/

1条回答
  •  执念已碎
    2021-01-14 01:27

    Ok spent some time pretty much getting better grip on Javascript.

    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.

    Ta

    0 讨论(0)
提交回复
热议问题