麻烦大家看一下下面这段代码,为什么页面一直出现undefined
var http = require ('http');
var qs = require('querystring');
http.createServer(function (req,res) {
if ('/'==req.url) {
res.writeHead(200,{'Content-Type':'text/html'});
res.end([
'<form action="/url" method="POST">',
'<h1>My form</h1>',
'<fieldset>',
'<label>Personal information</label>',
'<p>What is your name ?</p>',
'<input type="text" name="name">',
'<p><button>Submit</button></p>',
'</form>'
].join(' '));
} else if ('/url'==req.url && 'POST'==req.method) {
//创建一个字符串吸收数据块
var body = ' ';
req.on('data', function (chunk) {
body+=chunk;
});
//监听end事件
req.on('end', function () {
res.writeHead(200,{'Content-Type' : 'text/html'});
res.end('<p>Your name is <b>' +qs.parse(body).name+'</b></p>');
});
} else {
res.writeHead(404);
res.end('Not Found');
}
}).listen(3000);
两个婆娘一个郎
9 years, 3 months ago