【问题标题】:how to clear this error : UnhandledPromiseRejectionWarning: TypeError: callback is not a function如何清除此错误:UnhandledPromiseRejectionWarning: TypeError: callback is not a function
【发布时间】:2021-06-13 23:22:35
【问题描述】:

当我从 html 表单继续发布请求时,我的代码抛出此错误

UnhandledPromiseRejectionWarning:TypeError:回调不是函数。

我可以知道我应该做些什么修改来解决这个问题吗?

app.post('/profile', function (req, res) {
    var useremail = req.body.email;
    var password = req.body.psw;
    if (useremail && password) {
        dbconnect.query('SELECT * FROM customerdetails WHERE email = ? AND pws = ?', [useremail, password], function(error, results) {
      if ((results.length)== 0) {
        console.log(results.length)
        res.redirect('/error')
        //res.status(401).render('login',{msg:'Incorrect credentials'});
            } 
      else {
        //console.log(results[0].CHname);
        const id = results[0].CHID;
        //console.log(id);
        const token = jwt.sign({ id }, process.env.JWT_SECRET, {
          expiresIn: process.env.JWT_EXPIRES_IN
        });
  
        const cookieOptions = {
          expires: new Date(
            Date.now() + process.env.JWT_COOKIE_EXPIRES_IN * 1 * 5 * 60 * 1000
          ),
          httpOnly: true
        };
        res.cookie('biopay', token, cookieOptions);
        //console.log(req.cookies.jwt)
       dbconnect.query('SELECT * FROM carddetails WHERE CHID = ? ', [id], function(error, results1) {
          if ((results.length)== 0) {
            res.redirect('/error')
            //res.status(401).render('login',{msg:'Incorrect credentials'});
          } 
          else{
            console.log(results1)
            res.status(200).render('profile', { msg:results[0].CHname},{tables: results1})
        
          }
        })
        
            }           

【问题讨论】:

    标签: mysql node.js express


    【解决方案1】:

    答案是 res.status(200).render('profile', { msg:results[0].CHname},tables: results1});

    这是由于按照 res.render() 语法作为回调传递的表的值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-21
      • 2021-10-01
      • 2021-04-08
      • 2021-05-31
      • 2021-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多