【发布时间】:2018-01-31 10:00:18
【问题描述】:
我想知道如何让我的查询结果成为 Node.js 中的 JSON 响应。目前,我从我的数据库中获得了 JSON 格式的结果,但我无法访问其中的值。我的代码如下。
connection.connect();
connection.query('select * from ttnews order by post_date DESC Limit 0,10',
function (error, results, fields) {
if (error) throw error;
console.log(results);
});
connection.end();
responseJSON.response = results[0].headline;
callback(null, responseJSON);
通过responseJSON.response = results[0].headline 我收到错误results is undefined
任何帮助将不胜感激。
【问题讨论】:
-
您好,您可以提供您的方法的完整代码吗?你用
express吗?