此代码用于使用post form,保存数据和列表元素发送数据 在页面上。
首先,函数功能如果数据库有数据,它可以渲染到其他视图模板。[user.js]
var addstat = function(req, res) {
console.log('stat 모듈 안에 있는 addstat 호출됨.');
var database = req.app.get('database');
var paramid = req.param('id');
var paramround = req.param('round');
var paramgroup = req.param('group');
//var paramhomeImage = req.param('homeImage');
var paramhomeName = req.param('homeName');
var paramhomeScore = req.param('homeScore');
var paramhomeTotalShoot = req.param('homeTotalShoot');
var paramhomeValShoot = req.param('homeValShoot');
var paramhomeTotalpass = req.param('homeTotalpass');
var paramhomeValpass = req.param('homeValpass');
var paramhomeOffside = req.param('homeOffside');
var paramhomeCornerkick = req.param('homeCornerkick');
var paramhomeFoul = req.param('homeFoul');
//var paramawayImage = req.param('awayImage');
var paramawayName = req.param('awayName');
var paramawayScore = req.param('awayScore');
var paramawayTotalShoot = req.param('awayTotalShoot');
var paramawayValShoot = req.param('awayValShoot');
var paramawayTotalpass = req.param('awayTotalpass');
var paramawayValpass = req.param('awayValpass');
var paramawayOffside = req.param('awayOffside');
var paramawayCornerkick = req.param('awayCornerkick');
var paramawayFoul = req.param('awayFoul');
//image들 빠짐
if (database) {
addStat(database, paramid, paramround, paramgroup, paramhomeName, paramhomeScore,
paramhomeTotalShoot, paramhomeValShoot, paramhomeTotalpass,paramhomeValpass,
paramhomeOffside, paramhomeCornerkick,paramhomeFoul, paramawayName,
paramawayScore, paramawayTotalShoot, paramawayValShoot,paramawayTotalpass,
paramawayValpass, paramawayOffside, paramawayCornerkick, paramawayFoul,
function(err, result) {
if (err) {throw err;}
if (result) {
console.dir(result);
res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
// 뷰 템플레이트를 이용하여 렌더링한 후 전송
var context = {title:'사용자 추가 성공'};
req.app.render('addstat', context, function(err, html) {
if (err) {throw err;}
console.log("rendered : " + html);
res.end(html);
});
} else {
res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
res.write('<h2>경기 정보 추가 실패</h2>');
res.end();
}
});
} else {
res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
res.write('<h2>데이터베이스 연결 실패</h2>');
res.end();
}};
// ====错误消息==== //
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:38:20
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:39:23
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:40:23
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:43:26
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:44:27
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:45:32
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:46:30
Fri, 28 Oct 2016 07:49:36 GMT express deprecated req.param(name): Use req.params, req.body, or req.query instead at routes\user.js:47:31
然后,我用req.body改变了req.param。 但是,这台服务器对我说'
req.body未定义
我可以添加其他一些行吗? 我认为这是解析的问题。 你能让我知道吗。谢谢。