javascript - How to close Server-Sent Events events -
i want know how close server-sent events via javascript. below dummy code:
var ser=new eventsource("path"); ser.onmessage=function(ev){ if(!ev) //want close here!! else console.log(ev); }
the correct way close server side event close
method.
https://developer.mozilla.org/en-us/docs/server-sent_events/eventsource#method_overview
so you'd use:
var ser = new eventsource("path"); ser.onmessage = function (ev) { if (!ev) ser.close(); else console.log(ev); };
javascript case sensitive, can't use .close()
, it's different thing .close()
, undefined in case.
Comments
Post a Comment