- Messages
- 228
- Reaction score
- 13
- Points
- 38
Bago lang po ako sa socket.io and sa sinusundan ko na tut sa youtube meron po akong hindi makitang mali. na everytime na mag sesend ako ng
chat wala po lumalabas. and ang prob po e Uncaught ReferenceError: jquery is not defined
.
index.html
app.js
Sana po may makatulong sakin, maraming salamat po.
chat wala po lumalabas. and ang prob po e Uncaught ReferenceError: jquery is not defined
.
index.html
Code:
<!DOCTYPE html>
<html>
<head>
<title>Socket io Chat</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<style>
#chat {height: 500px;}
</style>
</head>
<body>
<div id="chat"></div>
<form id=send-message>
<input size="35" id="message"></input>
<input type="submit"></input>
</form>
[B]<script>
jquery(function($) {
var socket = io.connect();
var $messageForm = $('#send-message');
var $messageBox = $('#message');
var $chat = $('#chat');
$messageForm.submit(function(e) {
e.preventDefault();
socket.emit('send message', $messageBox.val());
$messageBox.val('');
});
socket.on('new message', function(data){
$chat.append(data + "<br/>");
});
});
</script>[/B]
</body>
</html>
app.js
Code:
var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);
server.listen(3000);
console.log('Tumatakbo na yung Server mo...');
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.sockets.on('connection', function(socket){
socket.on('sendmessage', function(data){
io.sockets.emit('newmessage', data);
});
});
Sana po may makatulong sakin, maraming salamat po.