我正在开发一个聊天程序,我还在开始制作它但是当我尝试从谷歌浏览器上的控制台连接到服务器时,它表示没有定义参考错误io。
客户端
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>Chat</title>
</head>
<body>
<div class="chat">
<input type="text" class="chat-name" placeholder="Enter your name">
<div class="chat-messages">
<div class="chat-message">
</div>
</div>
<textarea placeholder="type your message" class="chat-textarea"></textarea>
<div class="chat-status">Status: <span>Idle</span></div>
</div>
<script>src="http://localhost:8080/socket.io/socket.io.js"</script>
</body>
</html>
server.js
var mongo = require('mongodb').MongoClient,
client = require('socket.io').listen(8080);
console.log("Server is running on port 8080");
答案 0 :(得分:7)
因为这个原因:
<script>src="http://localhost:8080/socket.io/socket.io.js"</script>
它是标准的JS导入。它应该是这样的:
<script src="http://localhost:8080/socket.io/socket.io.js"></script>