Skip to content
Advertisement

While loops for server-sent events are causing page to freeze

I am currently working on a chat that uses Server-Sent Events to receive the messages. However, I am running into a problem. The server-sent event never connects and stays at pending because the page doesn’t load.

For example:

JavaScript

I expect that every 3 seconds, “data: This is the message.” will be outputted. Instead, the page just doesn’t load. However, I need this behavior for server-sent events. Is there a way to fix this?

Edit:

Full Code:

JavaScript

I would also like to note, that this infinite loop shouldn’t be causing this to happen. This is just how SSE’s are set up usually and it is even done so on the MDN website.

Advertisement

Answer

No doubt by now you have figured this out but on the offchance you have not I used code like the following on a couple of sse scripts and it worked like a charm. The code below is generic and does not feature your sql or recordset processing but the idea is sound(!?)

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