我在按下按钮后停止发送事件后,我试图重新启动服务器发送的事件。
所以我就这样停止了这个事件:
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();
});
有人可以就此提出建议吗?
任何帮助都将不胜感激。