[英]How To Fix Firebase Realtime Database v9 push method
I have made a HTML file test.html
, but after submitting it, it doesn't show any data.我做了一个HTML文件
test.html
,但提交后,它没有显示任何数据。 Am I doing something wrong, please assist me.我做错了什么,请帮助我。
Am using Firebase Realtime Database v9我正在使用 Firebase 实时数据库 v9
CODE代码
<head>
<script type="module">
import { initializeApp } from 'firebase/app';
import { getDatabase } from "firebase/database";
const firebaseConfig = {
apiKey: "*",
authDomain: "*.firebaseapp.com",
databaseURL: "https://*.firebaseio.com",
storageBucket: "*.appspot.com"
};
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
import { getDatabase, ref, push } from "firebase/database";
function writeMessageData() {
const db = getDatabase();
set(ref(db, 'data/'), {
name: document.getElementById("feildName").value,
msg: document.getElementById("feildMessage").value
});
}
</script>
<title>Test</title>
</head>
<body>
<input type="text" id="feildName" placeholder="Name">
<input type="text" id="feildMessage" placeholder="Message">
<button id="btnSubmit" onclick="writeMessageData()">SEND</button>
</body>
</html> ```
make your function async使您的 function 异步
async function writeMessageData() {
await set(ref(db,'ThePath'),{
name: document.getElementById("feildName").value,
msg: document.getElementById("feildMessage").value
}).then((success) => {console.log(success)}).catch((err) => {console.log(err)})
}
"data/"
to "data"
"data/"
更改为"data"
mostly it should work good luck.大多数情况下,它应该祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.