奇妙に聞こえるかもしれませんが、私は非常に単純な Web チャットを作成しようとしており、助けが必要です..
私はノードでここまでやってきました -
var http = require('http');
var fs = require('fs');
var path = require('path');
var messages = [];
// Simple Function to load HTML/JavaScript/CSS Files
function LoadHTML(html, requrl, res) {
var filePath = '.' + requrl;
if (filePath == './') {
filePath = './' + html;
}
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
}
fs.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
res.writeHead(500);
res.end();
}
else {
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}
});
}
else {
res.writeHead(404);
res.end();
}
});
}
http.createServer(function (req, res) {
LoadHTML('index.html', req.url, res);
}).listen(8125);
私が使用している HTML/CSS - http://jsfiddle.net/yZ5at/
ここから私は立ち往生しています..ユーザーがテキストエリアに何かを入力してEnterキーを押すと、彼のテキストがチャットdivに表示されるようにしたいです。
しかし、どうすればそれができますか?助けてください?