Created
January 5, 2013 11:00
-
-
Save sang4lv/4460999 to your computer and use it in GitHub Desktop.
Server sent events (SSE): Overview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var serverEvent = new EventSource("http://example.com/eventsource.php"); //CORS is supported | |
serverEvent.onerror = function(event) { | |
console.log(event.target.errorCode); | |
}; | |
serverEvent.onopen = function() { | |
console.log("Connection has been established"); | |
}; | |
serverEvent.onmessage = function(event) { | |
console.log("Message: " + event.data); //Data can be in JSON format. Use JSON.parse if so | |
}; | |
serverEvent.onnewconnection = function(event) { //User defined event | |
console.log("A new user has entered the chatroom."); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment