I'm trying to use EventSource in javascript. But as soon as I use them, i'm having some trouble. First, when reloading the page, the EventSource can't reconnect. Second, using it prevents XmlHttpRequests to work properly. In the below code, if I comment the event_source related code, the xml request works fine. If I create the event source and add a listener, the xml request never succeed.
envent_source = new EventSource('event-source.php');
envent_source.addEventListener('update', function(event) {
console.log("update event");
}, false);
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState == this.DONE) {
if (this.status == 200)
console.log("received");
}
}
request.open("GET", "document.xml");
request.send();
Did I missed something ? Do EventSource needs to be used with caution ?