2014-07-23 36 views
-3

我正在开发一个聊天程序,我还在开始制作它,但是当我尝试从谷歌浏览器的控制台连接到服务器时它表示没有定义参考误差io。node.js Socket io“引用错误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

我没有变量'io'在任何地方使用。它是你的完整代码吗? – Mritunjay

回答

7

这是因为这一点:

<script>src="http://localhost:8080/socket.io/socket.io.js"</script> 

这是一个标准的JS进口。它应该看起来像这样:

<script src="http://localhost:8080/socket.io/socket.io.js"></script> 
+0

哦伙计感谢lmao我延迟 – frosty