Fetching data from firebase web

I am trying to fetch the data for website using java script. Problem I am getting is that I am unable to get the key of Users-->Customers-->Key-->(name, phone). I am unable to find a syntax of it

Database image

Code I am trying is

 var fireheading = document.getElementById("fireHeading");


var firebaseHeadingRef = firebase.database().ref().child("Users").child("Customers").child(uid).child("name");



firebaseHeadingRef.on('value', function(datasnapShot){
    fireHeading.innerText = datasnapShot.val();
});

Upvotes: 1

Views: 864

Answers (1)

M.A.Williams
M.A.Williams

Reputation: 243

To get data from Firebase in javascript, you would do this:

var fireHeading = document.getElementById("fireHeading");
// "key" is the customer key
var ref = firebase.database().ref("Users/Customers/" + key);

ref.once("value", function(snapshot){
// Contains all data from Firebase
var data = snapshot.val();
// Has customer name
var customerName = data.Name;
// Has customer phone
var customerPhone = data.Phone;

// Append data to view
fireHeading.innerText = customerName;

});

This should work.

Upvotes: 4

Related Questions