Created
June 8, 2011 18:57
-
-
Save jhsu/1015080 to your computer and use it in GitHub Desktop.
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
<html><head><title>WebSocket Chat</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<form action="/send_message" method="post"> | |
<input type="text" name="message" id="message" /> | |
<input type="submit" id="send_message" value="send" title="send message" /> | |
</form> | |
<div id="messages"> | |
</div> | |
<script type='text/javascript'> | |
$(document).ready( function(){ | |
var ws = new WebSocket("ws://echo.websocket.org"); | |
var messages = $("#messages"); | |
ws.onmessage = function(evt) { | |
messages.append("<p>you: "+evt.data+"</p>"); | |
} | |
$('#send_message').click( function(evt) { | |
evt.preventDefault(); | |
message = $('input#message'); | |
ws.send(message.val()); | |
message.val(''); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment