Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Closure find node.js、mongodb、express_Node.js_Mongodb_Express_Closures - Fatal编程技术网

Closure find node.js、mongodb、express

Closure find node.js、mongodb、express,node.js,mongodb,express,closures,Node.js,Mongodb,Express,Closures,请帮帮我。我的搜索使用帖子中需要变量: 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

请帮帮我。我的搜索使用帖子中需要变量:

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进行网站搜索。

我认为您无法使用
post
方法重定向(如果我了解您在寻找什么)。如果您想通过变量使用会话,可以这样说:谢谢您的关注,但我的代码没有得到答案…我使用搜索,但我的代码使用html中的post,因此数据不会显示在get中..您不能以这种方式初始化
测试
变量<代码>a
将是未定义的。是的,在我的代码中有2个方法post和get,对于输入数据使用post,对于显示数据使用get..但是我在post方法中有问题,因为我的变量在get方法中没有..使用会话,在后期阶段存储变量并在get阶段检索它。您好,谢谢您的帮助我得到了我的问题兄弟我的数据不在变量a中,我在find data use db.collection('ak_test_score',function(err,collection){collection.findOne({'std_id':{'regex':id_school},function(err,level){和它的工作感谢ubut我有新问题lol..如果我的search=null我的node.js是stack…我使用if(level=null){}else{}我的app.undefined T hik hik
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;
        app.set('data',a);
        var b = level.school_name;

        });
});
   res.redirect('/test_score'); ///// send to my page to get
};


 app.get('/test_score', function(req, res) {
    var id_school = app.get('data');
    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)
        });
});

};