2017-07-11 44 views
0

我想從node.js重新渲染一個jade以設置錯誤消息。 我收到錯誤「發送後無法設置標題」。Node.js登錄表單渲染:錯誤發送後無法設置標題

這是我的代碼...

app.post('/login', function (req, res) { 
    checkUserAndPassword(req.body.mail, req.body.password, function (status) { 
     console.log(status); 

     if (status === 1) { 
      getInstances(function (instances) { 
       res.render('mainSite', {title: "Systemverwaltung - Übersicht", instances: instances}); 
      }); 
     } else { 
      res.render('index', {title: "Systemverwaltung", error: "Wrong Mail or Password!"}); 
     } 
    }); 
}); 

有沒有人的想法?

+3

可能重複的[錯誤:發送到客戶端後無法設置標頭](https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent -to-的客戶端) –

回答

0

通過查看您提供的代碼似乎沒有任何問題。這意味着問題可能在其他地方。

,可能會導致這些症狀可能出現的問題:

  1. checkUserAndPassword調用回調兩次
  2. getInstances調用回調兩次
  3. 一些中間件已經發送您的處理程序之前響應

中當然,這些都不是這種情況,不可能知道沒有看到那些代碼,但這些將是我開始調查問題的線索。

相關問題