更改 Server-Sent 事件的来源 (url)

5 javascript php server-sent-events

如何更改声明中的源集EventSource

我试过这样的事情:

var source = new EventSource("/blahblah.php?path=" + (window.location.pathname));
// Few lines later...
source.url = "/blahblah.php?path=" + url;
Run Code Online (Sandbox Code Playgroud)

但是,source.url还是一样...

这甚至可能吗?或者也许有其他方法可以做到这一点?

gue*_*314 5

不,这是不可能的。传递给的新 URLEventSource() 创建一个新EventSource对象。