I am new to the v9 of Firebase so i am using the new functions. I am trying to insert data into RealTime Database of Firebase, using SET.
FIRST IMPORT AND INITIALIZE THE VARIABLES
<script type="module">
// Import the functions you need from the SDKs you need
const myfrom = document.getElementById("rateF");
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-analytics.js";
import { getDatabase, ref, set, push } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-database.js";
const firebaseConfig = {
...
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const database = getDatabase(app);
Than i start the actual function called on submit
myfrom.addEventListener ("submit",(e) =>validate());
function validate(){
var select = document.getElementById('titolo');
var value = select.options[select.selectedIndex].value;
var comment = document.getElementById('comm').value;
var radio = getValueRadio();
console.log(value);
console.log(comment);
console.log(radio);
sendMessage(value,comment,radio);
}
THE FUNCTION WHERE I USE SET
function sendMessage(value,comment,radio){
const db = getDatabase();
const postListRef = ref(database,"comment");
set(postListRef,{
from: "admin",
film: value,
comment: comment,
rate: radio
})
.then(()=>{
alert("Commento Inviato");
})
.catch((error)=>{
alert("error");
console.log(error)
});
}
function getValueRadio(){
...
}
</script>
The set actually doesn't send any alert of any kind. The functions just start anf finish with no errors but the data is not inserted. What am i doing wrong ?