【发布时间】:2013-02-06 08:05:58
【问题描述】:
我正在尝试使用彗星来实现聊天。由于我没有任何彗星经验,因此我搜索了示例代码,并找到了this site
创建所有文件后,我得到了这个模棱两可的错误
未捕获的 ReferenceError:未定义要求(chrome 控制台)
ReferenceError:未定义要求 var http = require('http');(firefox 控制台)
这是因为我在 localhost 服务器上测试此代码还是有其他问题? html代码是:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Comet Test</title>
</head>
<body>
<p><a class='customAlert' href="#">publish customAlert</a></p>
<p><a class='customAlert2' href="#">publish customAlert2</a></p>
<script src="http://localhost:80/chekhabara/downloads/realtime/2/jquery.min.js" type="text/javascript"></script>
<script src="http://localhost:80/chekhabara/downloads/realtime/2/NovComet.js" type="text/javascript"></script>
<script type="text/javascript">
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, '127.0.0.1');
console.log('Server running at http://127.0.0.1:80/');
</script>
</body>
</html>
【问题讨论】:
-
这是node.js 代码。你不要把它放在一个 HTML 文件中——你必须运行一个特殊的 node.js 服务器。
-
您的代码似乎与您链接的内容无关。
-
他正在尝试运行节点服务器,那是他的 sn-p。
-
@AlienWebguy:不,那是一个 HTML 文件。
-
不,这不是 node.js 我知道什么是 node.js,我不想使用那种技术。它是 jquery 库 NovComet.js
标签: php javascript comet