Change source (url) of Server-Sent event

[亡魂溺海] 提交于 2019-11-30 15:38:20

No, it is not possible. A new URL passed to EventSource() creates a new EventSource object.

guest271314 suggested me much solutions to this, but for me it would be much better, faster and less complicated to stay with sse.

I changed the source by closing and removing (all are necessary) the source var.

This is how I did it:

source.url = "/blahblah2.php";

source.close();
delete source;

//Redefine source

IMPORTANT: This won't work if you defined source with var! Redefinition should also go without it!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!