Skip to content

Instantly share code, notes, and snippets.

@marcmartino
Created July 2, 2012 21:50
Show Gist options
  • Save marcmartino/3035944 to your computer and use it in GitHub Desktop.
Save marcmartino/3035944 to your computer and use it in GitHub Desktop.
<script>
if (!!window.EventSource) {
var source = new EventSource('serverSentEvent.php');
} else {
// Result to xhr polling :(
}
source.addEventListener('message', function(e) {
console.log(e.data);
}, false);
source.addEventListener('open', function(e) {
// Connection was opened.
}, false);
source.addEventListener('error', function(e) {
if (e.readyState == EventSource.CLOSED) {
// Connection was closed.
}
}, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment