你好,有人可以幫助我。我試圖做一個簡單的註冊登錄網站,我不能將響應傳入我的回調我已經累了bind()
和一個全局變量。問題是res.writeHead()
Node.js將一個變量傳遞給回調
http.createServer(function (req,res){
var body = '';
if(req.method='POST'){
req.on('data',function(chunk){
body+=chunk;
});
req.on('end',function(){
console.log('POSTED: ' + body);
var content = body.split('&');
if(content[0].split('=')[0] == 'login')
{
connectDB(dbURL,function(){
User.findOne({
'username':content[1].split('=')[1],
'password':content[2].split('=')[1]},
function(err,loginUser){
console.log(loginUser);
if (loginUser != null)
{
res.writeHead(301,{Location: './page.html'});
res.end();
}
db.close();
});
});
您是否嘗試過使用像express.js這樣的框架?可能更容易使用... – CreasolDev
你得到的錯誤信息是什麼?我也建議使用快遞。 – Louy
是的,我知道它更容易,我一定會使用express.js,但首先我想從頭學習的東西。並沒有錯誤味精程序符文通常它只是不會重定向到page.html網站 – BlackIce