Javascript 当我的查询结果行数为0时,如何检查节点js中响应的抛出错误
如果我的行数为o,我需要将res作为失败发送。如果我的行数是 1我需要将res状态发送为success。请帮帮我。当我 试图将print(client.query)作为json(在 (附图)Javascript 当我的查询结果行数为0时,如何检查节点js中响应的抛出错误,javascript,angularjs,node.js,Javascript,Angularjs,Node.js,如果我的行数为o,我需要将res作为失败发送。如果我的行数是 1我需要将res状态发送为success。请帮帮我。当我 试图将print(client.query)作为json(在 (附图) 如果我正确理解了您的要求,那么您应该拥有如下代码: var query = client.query("select * from pp_user_profile where email_id = '"+req.query.email_id+"' and user_password= '"+req.qu
如果我正确理解了您的要求,那么您应该拥有如下代码:
var query = client.query("select * from pp_user_profile where email_id = '"+req.query.email_id+"' and user_password= '"+req.query.user_password+"'");
query.on("end", function (result) {
if (result.rows.length === 0) {
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Failed');
res.end();
}
else{
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Success');
res.end();
}
如果我正确理解了您的要求,那么您应该拥有如下代码:
var query = client.query("select * from pp_user_profile where email_id = '"+req.query.email_id+"' and user_password= '"+req.query.user_password+"'");
query.on("end", function (result) {
if (result.rows.length === 0) {
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Failed');
res.end();
}
else{
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Success');
res.end();
}
将if…else条件更改为这种方式
if(result.rowCount === 1){
// your code goes here
}
else{
// your code goes here
}
将if…else条件更改为这种方式
if(result.rowCount === 1){
// your code goes here
}
else{
// your code goes here
}
@subburaj..如果我在查询中得到1条记录。我需要将响应状态发送为成功。如果我得到0,则在我的数据库中找不到用户,因此我将发送失败响应。@subburaj..如果我在查询中得到1条记录。我需要将响应状态发送为成功。如果我得到0,则在我的数据库中找不到该用户,因此我将发送失败响应。