I was working on socket.io and started with working on a chat services.
Everything worked fine on the server side but upon trying to connect to
the /socket.io/socket.io.js on the client side by using var socket = io.connect();
it says that “io is not defined; please fix or add /global io/”.
<!doctype html>
<html>
<head>
<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>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
jQuery(function ($) {
var socket = io.connect(); <----"io is not defined; please fix or add /*global io*/"
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>
</body>
</html>