Display alert message in browser using Node.js

Jay*_*nth -2 node.js

I need to display an alert message in browser using Node.js code. Here my code

app.post('/logon', function (req, res)
   {
      var user=req.body.userName;
      var password=req.body.password;
      if((user=='admin')&&(password=='admin'))
         { 
              //redirect to home page
          }
       else
          {
                //here I need to display a alert message in browser saying that invalid user name or password is wrong
           }
       ..........
Run Code Online (Sandbox Code Playgroud)

sur*_*jck 8

如果您使用的ajax是将用户名和密码发送到节点服务器,那么您可以执行此操作

app.post('/logon', function (req, res)
{
  var user=req.body.userName;
  var password=req.body.password;
  if((user=='admin')&&(password=='admin'))
      //redirect to home page
  else
      res.send(500,'showAlert') 
Run Code Online (Sandbox Code Playgroud)

在服务器和error客户端的ajax 的功能,做

error: function(error){
          if(error.responseText == 'showAlert')
              alert("Please enter correct user name and password.")
Run Code Online (Sandbox Code Playgroud)

就像Felix Kling指出的那样,这需要在客户端执行.