I've been playing with nodejs, using websockets to communicate between server and browser. This is my working client code:
<script src="https://cdn.socket.io/socket.io-1.3.7.js"></script>
<script>
var socket = io();
socket.on('ida',function(data){
console.log(data.news);
socket.emit('vuelta',{news: 'answer'});
});
</script>
Then why if I put
var socket = io();
socket.on('ida',function(data){
console.log(data.news);
socket.emit('vuelta',{news: 'answer'});
});
in a separated client.js file and link it like
<script src="https://cdn.socket.io/socket.io-1.3.7.js"></script>
<script src="client.js" type="text/javascript"></script>
it just doesn't work? In the browser's console, instead of showing data.news it says: Uncaught SyntaxError: Unexpected token < in client.js:1