1.我在routes/index.js中添加了提取表单内容
exports.doSearch = function(req, res){
//console.log(req.params.doSearch);//输出index
var namevalue = req.body.username;
console.log(namevalue);//输出表单post提交的login_name
res.send(‘great you are right for post method:’ + namevalue);//显示页面文字信息
return namevalue;
};
2.我在另外一个文件search.js文件中想引用index.js中的namevalue值
var searchResult = require(‘./routes/index’);
var myname = searchResult.doSearch();
发现报错:
C:\project\ex03\routes\index.js:21
var namevalue = req.body.username;
^
TypeError: Cannot read property ‘body’ of undefined
at Object.exports.doSearch (C:\project\ex03\routes\index.js:21:21)
at Object.<anonymous> (C:\project\ex03\search.js:8:28)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
3.请问我怎样才能将namevalue传出来?
5 回复