【问题标题】:node.js Socket io "Reference error io is not defined"node.js Socket io“未定义引用错误io”
【发布时间】:2014-09-14 15:15:33
【问题描述】:

我正在开发一个聊天程序,我仍在开始制作它,但是当我尝试从谷歌浏览器上的控制台连接到服务器时,它说参考错误 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");

【问题讨论】:

  • 我没有在任何地方使用变量io。这是你的完整代码吗?

标签: javascript html node.js mongodb socket.io


【解决方案1】:

因为这样:

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

这是一个标准的 JS 导入。它应该是这样的:

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

【讨论】:

    猜你喜欢
    • 2013-07-22
    • 2016-01-29
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 2011-08-03
    • 2018-07-30
    • 1970-01-01
    • 2012-05-20
    相关资源
    最近更新 更多