首页 > 解决方案 > 以角度读取节点表达的响应

问题描述

我正在尝试使用 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"
          });
    }
  }
  });
}); 

标签: mysqlnode.jsjsonangularexpress

解决方案


推荐阅读