使用 Node.js 在浏览器中显示警报消息
Display alert message in browser using Node.js
我需要使用 Node.js 代码在浏览器中显示警告消息。这是我的代码
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
}
..........
如果您使用 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')
在服务器端和客户端ajax的error
函数中,做
error: function(error){
if(error.responseText == 'showAlert')
alert("Please enter correct user name and password.")
正如 Felix Kling 指出的那样,这需要在客户端执行。
我需要使用 Node.js 代码在浏览器中显示警告消息。这是我的代码
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
}
..........
如果您使用 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')
在服务器端和客户端ajax的error
函数中,做
error: function(error){
if(error.responseText == 'showAlert')
alert("Please enter correct user name and password.")
正如 Felix Kling 指出的那样,这需要在客户端执行。