Sir George
Sir George

Reputation: 433

Showing Firebase records in an HTML web page

I am trying to query Firebase records in my HTML page, but I haven't found any luck by now.

I am using JavaScript and here is the current code that I have. Is there a proper way to output the records? I understand it is a JSON formatted file.

var ref = new Firebase("https://ngong-hills.firebaseio.com/Bookings");
ref.orderByChild("Bookings").on("child_added", function(snapshot) {
    console.log(snapshot.key());
    document.write(snapshot.key());
});

Is there anything i am missing??

Upvotes: 1

Views: 915

Answers (1)

Artem Dudkin
Artem Dudkin

Reputation: 588

Looks like you are using very old tutorial, as

  1. initialization looks different now, and
  2. you do not just show data, you show it in case of some change, so you will not see anything in there is no changes

This code works for me

<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase.js"></script>

<script>
    var config = {
        apiKey: "***",
        authDomain: "crackling-fire-7458.firebaseapp.com",
        databaseURL: "https://crackling-fire-7458.firebaseio.com"
    }
    var app = firebase.initializeApp(config);

    var ref = app.database().ref('/');

    ref.on('value', function(snapshot) {
        console.log(snapshot.val());
    });
</script>

Upvotes: 1

Related Questions