HTML5:停止后重新启动SSE?

时间:2016-11-09 09:41:49

标签: javascript html5

我在按下按钮后停止发送事件后,我试图重新启动服务器发送的事件。

所以我就这样停止了这个事件:

if(typeof(EventSource)!=="undefined") {
    //create an object, passing it the name and location of the server side script
    var eSource = new EventSource("mypage.php");
    //detect message receipt
    eSource.onmessage = function(event) {
        //write the received data to the page
        document.getElementById("serverData").innerHTML = event.data;

        if(event.data !=""){

        alert('success');

       ///Close it here///////////
        event.target.close();



        }

    };
}
else {
    document.getElementById("serverData").innerHTML="Whoops! Your browser doesn't receive server-sent events.";
}

现在我需要像这样重新启动相同的SSE(如果可能的话):

$('#someBtn').click(function(){ 

//////this is actually my assumption and there is no such a function///
event.target.start();

});

有人可以就此提出建议吗?

任何帮助都将不胜感激。

0 个答案:

没有答案