【发布时间】:2016-02-22 18:16:17
【问题描述】:
我用 node.js 创建了一个服务器。然后我在特定地址上构建一个 http 表单。 (我将在不同的地址上做不同的表格)。 我想从特定领域的用户那里接收数据。 (我会给他们不同的ID)。
但我无法通过 document.getElementById() 接收它,因为 DOM 在 node.js 中未定义。
你能推荐一个特定的模块来解决这个问题,或者一些有用的方法吗?
var server = new http.Server(function(req, res){
if (req.url=='/') {
res.statusCode=200;
auth(res);
res.end();
} else {
res.statusCode=404;
res.end("Page not found");
}
})
function auth(res) {
res.writeHead(200, {
'Content-Type': 'text/html',
});
var body = '';
body= '<form action="/" method="post">'+
'<thead>Connection details </thead>' +
'<br>'+
'<textarea id ="text" name="text" rows="1" cols="50"></textarea><br>'+
'<input value="localhost" id="host">Host</input><br>' +
'<input value="root" id="user">User </input><br>' +
'<input value="********" id="pass">Pasword </input><br>' +
'<input type="submit" value="Connect" id="scheme"></input><br></body></html>'
var toWrite = header + body;
res.write(toWrite);
}
【问题讨论】:
标签: javascript node.js