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...");
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745672803a4639509.html
评论列表(0条)