admin管理员组文章数量:1435859
How can I change the source set in declaration of EventSource
?
I have tried something like this:
var source = new EventSource("/blahblah.php?path=" + (window.location.pathname));
// Few lines later...
source.url = "/blahblah.php?path=" + url;
But, source.url
stays the same...
Is this even possible? Or maybe there are alternative ways to do that?
How can I change the source set in declaration of EventSource
?
I have tried something like this:
var source = new EventSource("/blahblah.php?path=" + (window.location.pathname));
// Few lines later...
source.url = "/blahblah.php?path=" + url;
But, source.url
stays the same...
Is this even possible? Or maybe there are alternative ways to do that?
Share Improve this question asked Feb 24, 2017 at 18:50 user5147563user51475632 Answers
Reset to default 5No, it is not possible. A new URL passed to EventSource()
creates a new EventSource
object.
I Do it like this.
var source;
function ChangeEventSource(Url) {
if (source != undefined) {source.close(); }
if (typeof (EventSource) !== "undefined") {
source = new EventSource(Url);
source.onmessage = function (event) {
//Do something here
};
} else {
console.log("Sorry, your browser does not support server-sent events...");
}
}
本文标签: javascriptChange source (url) of ServerSent eventStack Overflow
版权声明:本文标题:javascript - Change source (url) of Server-Sent event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745672803a2669674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论