Я пытаюсь читать и показывать данные из моей базы данных Firebase разными способами, но не могу заставить их работать.В моей базе Firebase есть следующая структура: База данных Firebase
И это весь код js:
var config = {
apiKey: "thecharactersoftheapikey",
authDomain: "xyxyxyxyxyxyxy.firebaseapp.com",
databaseURL: "https://xxxxxxxxxxx.firebaseio.com",
projectId: "xyxyxyxyxy",
storageBucket: "xxxxxxxxxx.appspot.com",
messagingSenderId: "12345678"
};
firebase.initializeApp(config);
/*If user is logged or Not and get the user email to display*/
firebase.auth().onAuthStateChanged(function(user) {
var name, email, picture;
if (user) {
name = user.displayName;
uid = user.uid;
email = user.email;
//picture = user.photoURL;
//document.getElementById("user-image").src = picture;
document.getElementById("user-name").innerHTML = email;
}else {
document.getElementById("members-area").style.display="none";
}
});
/*To Log out */
function singOut(){
firebase.auth().signOut().then(function() {
// Sign-out successful.
location.href="http://localhost/xxx/index.html";
}).catch(function(error) {
// An error happened.
});
}
/*Retrieving data from the database*/
var usersRef = firebase.database().ref('users');
usersRef.on('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
console.log(childData);
});
});
В console.log ничего не отображается.
Примечание. Я уже пытался использовать «child_added» вместо «value», и он не работает.