【发布时间】:2013-08-01 21:27:12
【问题描述】:
请帮助我。我的搜索使用帖子中需要变量:
app.post('/find', function(req, res) {
var id_school = req.body.std_id;
console.log('show '+ id_sekolah);
db.collection('ak_test_score', function(err, collection) {
collection.find({'std_id':id_school}).toArray(function(err, level) {
var a = level.std_id;
var b = level.school_name;
});
});
res.redirect('/test_score'); // send to my page to get
};
var test = a; // not defined variable a not have
app.get('/test_score', function(req, res) {
var id_school = test;
console.log('show '+ id_sekolah);
db.collection('ak_test_score', function(err, collection) {
collection.find({'std_id':id_school}).toArray(function(err, level) {
res.send(level)
});
});
};
我正在使用它来使用帖子进行网站搜索。
【问题讨论】:
-
我认为您无法使用
post方法重定向(如果我了解您在寻找什么)。如果你想传递变量使用会话,像这样:stackoverflow.com/questions/5599083/… -
感谢您的关注,但我的代码没有得到答案...我用于搜索,但我的代码使用 html 中的帖子,因此数据不会显示在 get..
-
你不能用这种方式初始化
test变量。a将未定义。 -
是的,在我的代码中有 2 个方法 post 和 get,输入数据使用 post 和显示数据使用 get..但是我无法关闭 post 方法中的变量,而 get 方法中没有..
-
使用会话,在后期存储变量并在获取阶段检索它。
标签: node.js mongodb express closures