簡體   English   中英

如何將數據從腳本發送到 HTML 頁面?

[英]How to send the data from the script to HTML page?

我正在使用 Firebase 來獲取數據

代碼:

const admin = require('firebase-admin');
const serviceAccount = require("C:/Users/santo/Downloads/bestmpos-firebase-adminsdk.json");

admin.initializeApp({
 credential: admin.credential.cert(serviceAccount)
});

let fs = admin.firestore();
let auth = admin.auth();

const listAllUsers = async (nextPageToken) => {
  try {
    let result = await auth.listUsers(100, nextPageToken);
    result.users.forEach((userRecord) => {
      start(userRecord.toJSON())
    });
    if (result.pageToken) {
      listAllUsers(result.pageToken);
    }
  } catch(ex) {
      console.log('Exception listing users:', ex.message);
  }
}

async function first(){
    await listAllUsers();
}
first();

async function start (object){
  const info = await fs.collection('users').doc(object.uid).get();
  if (!info.exists) {
    console.log('No document');
   } else {
    console.table([info.data()]);
    document.getElementById("greeting").innerHTML = info.data().toString();

   }
} 

HTML 代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<script type="text/javascript" src="app3.js"></script>
</head>
<body>
    <p id="greeting"></p>
</body>
</html>

但我想將數據console.log(info.data())發送到 HTML 頁面以簡單地顯示信息,

我該怎么做,我不想使用反應或任何其他人可以幫助我嗎? 我也是這個 Nodejs 還是普通的 javascript?

您可以使用innerHTML在您的 html 中發送數據。

像這樣:

document.getElementById("yourElementId").innerHTML = info.data();

這對我有用:

<p id="greeting">

</p>

<script>
    document.getElementById("greeting").innerHTML = "test"
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM