繁体   English   中英

从Firebase检索数据无法正常工作

[英]Retrieving data from Firebase for web not working

我正在尝试使用多种方法读取和显示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”,但是它不起作用。

问题是我数据库上的规则不允许从任何来源进行读/写。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM