我遇到请求发射器确实发出“数据”事件但不发出“结束”事件的情况。我不确定如何排除故障。你会怎么做?
var Review = require('../lib/review')
, qs = require('querystring');
exports.processReview = function(req, res){
var body = '';
req.setEncoding('utf8');
req.on('data', function(chunk){body += chunk});
req.on('end', function(){
console.log('got here: ' + body);
var obj = qs.parse(body);
var review = new Review({
title: obj.param('title'),
content: obj.param('content'),
submittedBy: obj.param('submittedBy'),
recommendedFor: obj.param('recommendedFor')
});
console.log('New Review: ' + JSON.stringify(review));
res.end('Ok\n');
});
res.end('Ok\n');
console.log('_________end______' + body);
};
exports.displayForm = function(req, res){
var html = '<html><head><title>some head</title></head><body><h1>Review Form</h1>'
+ '<form method="post" action="/process/review" >'
+ '<p>Title: <input type="text" name="title" /></p>'
+ '<p>Content: <input type="text" name="content" /></p>'
+ '<p>Nickname: <input type="text" name="submittedBy" /></p>'
+ '<p>Recommended for: <input type="text" name="recommendedFor" /></p>'
+ '<p><input type="submit" value="Submit Review" /></p>'
+ '</form></body></html>';
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', Buffer.byteLength(html));
res.end(html);
};
您将如何解决此问题?问题是什么?谢谢你