我建立了2个文件。在第一个文件中,我使用 nodejs 从数据库中获取一些数据,在第二个文件中,我有一个简单的 html 标记,我想在其中插入来自 nodejs 文件(index.js)的数据。在我的 html 文件result
中,插入哪个是正确的方法console.log(result);
<h1 id="result"></h1>
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("Test");
dbo.collection("users").find({}, { "name":"John" }).toArray(function(err, result) {
if (err) throw err;
console.log(result);
db.close();
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="./index.js"></script>
<title>Document</title>
</head>
<body>
<h1 id="result"></h1>
</body>
</html>
那么,如何result
从 index.js 插入 index.html 文件<h1 id="result"></h1>
?