Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

313
Views
function Set of Firebase to insert data in RealTime Database is not working in Javascript

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 ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!