[英]Node.js passing a variable into a callback
大家好,有人可以帮我吗。我试图建立一个简单的注册登录站点,但我无法将响应传递到回调中,因为我已经厌倦了bind()
和全局变量。问题是res.writeHead()
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();
});
});
我想问题是
if (loginUser != null)
你试过了吗
if (loginUser !== null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.