Created
November 12, 2011 08:37
-
-
Save jafstar/1360254 to your computer and use it in GitHub Desktop.
Simplest Chat Room - Client
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Simplest Chat Room</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var socket = io.connect('http://theDomain.com'); | |
socket.on('news', function (data) { | |
console.log(data); | |
socket.emit('my other event', { my: 'data' }); | |
}); | |
function sendMsg(){ | |
var theMsg = $('#theMsg').val(); | |
socket.emit('newMsg', { theMsg: theMsg }); | |
$('#theMsg').attr('value',''); | |
} | |
socket.on('writeMsg', function (data) { | |
console.log(data.theMsg); | |
$('#messages ul').append('<li>'+data.theMsg+'</li>'); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="messages"> | |
<ul> | |
<li>Welcome to the chat room</li> | |
</ul> | |
</div> | |
<input type="text" id="theMsg"> | |
<input type="button" value="Send" id="theBtn" onclick="sendMsg()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment