Skip to content
Advertisement

EventSource onmessage() is not working where onopen() and onerror() works properly?

check my code below, Here I have added three alert messages to each event type, but in this code source.onopen()[alert: readyState: 1] and source.onerror()[alert: readyState: 0] works properly but in case of onmessage() it is not executed.`

JavaScript

check the code below for the server side

JavaScript

I am using STS(Spring tool Suits), I am wondering, when I am using ctrl+space on EventSource (source) object, in the options it only shows onopen() and onerror(), where is the onmessage().

I will be highly appreciate, if I’d get any response. –Thanks

Advertisement

Answer

Solved it !!!

There is no issue with code, the actual issue is when I am writing response to client my response message should look like as below.

JavaScript

In my code I was missing the last part “nn” in response object so source.onmessage(datalist) in javascript didn’t get hit.

Crazy coding..

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement