我正在尝试使用node.js从sqlite数据库查询数据,当我运行它时一切都进行得很顺利,并将输出打印到控制台,但是我想将数据库中的输出数据放入HTML元素(例如p元素)中,但这对我不起作用!
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
</head>
<body>
<p id="para"></p>
<script type="text/javascript">
var fullname;
var fname = "bishoy";
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('./test.db');
let sql = `SELECT Id,
Name,
Age,
BloodGroup
FROM donor
WHERE Name = ?
ORDER BY Name`;
db.each(sql, [fname], (err, row) => {
if (err) {
throw err;
}
fullname = (`${row.Name}`);
callback(fullname)
});
function callback(fullname){
document.getElementById('para').innerHTML = fullname
}
db.close()
</script>