'Detect change of readyState with SSE

I am using HTML5 Server-Sent events:

SSEUpdate = new EventSource("update.php");

I want to detect when SSEUpdate.readyState changes. I've tried .onerror, but when I use console.log(SSEUpdate.readyState), I always get 0. I want to run my function when readyState changes to 2.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source