Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我的查询结果行数为0时,如何检查节点js中响应的抛出错误_Javascript_Angularjs_Node.js - Fatal编程技术网

Javascript 当我的查询结果行数为0时,如何检查节点js中响应的抛出错误

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

如果我的行数为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.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,则在我的数据库中找不到该用户,因此我将发送失败响应。