我正在尝试用MEAN(Mysql,Express,Angular,Node)登录表单。我在阅读节点的响应并相应地显示消息时遇到了问题。需要一些帮助来调查这个问题。
这些if else条件也不起作用。救命啊!!!!
postmethod(post)
{
this._http.login(post).subscribe(
(resp) => {
if(resp) this.response = resp;
console.log( resp );
//this resp(in json format) is ok.....need code(from resp json) from it..Also these if else blks are not working correct. //
var ccode = this.response.code;
if(ccode = 200)
{ this.qresult = 'Login Succesfull'; }
else if (ccode = 202)
{
this.qresult = 'Email and password does not match';
}
else
{
this.qresult = 'Email does not exits';
}
this.data_enter = true;
console.log("this.response.code);
console.log("Success From Login Method");
});
}
节点函数
app.post('/login' , jsonParser , function(req, resp)
{
var username= req.body.username;
var password = req.body.password;
connection.query('SELECT * FROM users WHERE username = ?',[username], function (error, results, fields) {
if (error) {
// console.log("error ocurred",error);
resp.send({
"cod+hgee":400,
"failed":"error ocurred"
})
}else{
if(results.length >0){
console.log(results[0]);
if(results[0].Password == password){
resp.send({
code : "200",
"success":"login sucessfull"
});
}
else{
resp.send({
code:"202",
"success":"Email and password does not match"
});
}
}
else{
resp.send({
code:"204",
"success":"Email does not exits"
});
}
}
});
});
1条答案
按热度按时间w6mmgewl1#
这个问题得到了回答。提问者使用赋值(=)进行比较