2013-10-28 71 views
0

我必須使用response.writehead重定向到不同的頁面。我怎樣才能做到這一點在SQL查詢。如何在連接數據庫時使用node.js中的響應?

這是我的代碼。

socket.on('login_check', function(email, pwd) { 
    connection.query("SELECT id,user_type FROM user WHERE email = '"+email+"' AND password = '"+pwd+"'ORDER BY name ", 
    function (error, results, fields) { 
     if (error) { 
      console.log(error); 
     } 
     if (results[0]) { 
      // some code  
     } else { 

      // Have to use response.writehead here. Please guide how to do this. If i use it here directly then it will give response is undefined error. 

     } 
    }); 
}); 

回答

0

它看起來像我使用socket.io,沒有響應傳統的HTTP請求。因此你沒有使用「響應」對象。我建議您使用socket.emit()通過套接字發送消息回客戶端,並使用客戶端JavaScript手動更改window.location

+0

這不會服務我的目的。 Actuall我的問題是http://stackoverflow.com/questions/19567721/refresh-window-when-username-and-password-mismatch – Vardan

相關問題