0

I just got into Firebase and I´m trying to retrieve data from the realtime database, but I can't get anything to show up on the webpage.

This is what I got, before the JS I got the initialize Firebase code. (IF I delete the val() I receive [object Object] so something is at least working).

JS:

var heading = document.getElementById("head");

var firebaseHeadingRef = firebase.database().ref().child("Heading");

firebaseHeadingRef.on('value', function(datasnapshot) {
    heading.innerText = datasnapshot.val();
});

HTML:

<div id="table_body"> <h1 id="head">Some Text</h1>

This is a screenshot from the database:

1

I appreciate all help :)

2 Answers 2

1

The Realtime Database is case sensitive. In your DB screenshot you have Heading but your JS code has .child('heading'). Try making those the same case and it should work. Note that you must also have appropriate Security Rules to allow access for unauthenticated users.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thank you for the answer. I changed the h to upper case, but it didn't help. I have the security rules on both read and write set to true.
0

I sort of faced a similar issue, everything was fine including the database rules but no data was being fetched.

My solution

My configuration containing the apiKey & projectId was missing the databaseURL portion, so I recopied the correct configuration & it worked.

P.S

Try checking your console for any warnings from Firebase

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.