I have made a HTML file test.html
, but after submitting it, it doesn't show any data. Am I doing something wrong, please assist me.
Am using Firebase Realtime Database 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
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"
mostly it should work good luck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.