【发布时间】:2017-09-23 21:54:18
【问题描述】:
我刚刚开始使用 firebase 和 javascript html 为我的应用创建网站。
我要做的就是从 firebase 访问任何值并将其打印在网站上。
我按照 firebase 的快速入门教程复制了与他们完全相同的代码:https://www.youtube.com/watch?v=k1D0_wFlXgo
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Javascript</title>
</head>
<body>
<h1 id="bigOne"></h1>
<script src="https://www.gstatic.com/firebasejs/3.3.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyD0C9hhfpdKEIahisG0VNInZZGjCyf5Lo0",
authDomain: "game-of-chats-ce897.firebaseapp.com",
databaseURL: "https://game-of-chats-ce897.firebaseio.com",
storageBucket: "game-of-chats-ce897.appspot.com",
};
firebase.initializeApp(config);
var bigOne = document.getElementById('bigOne');
var dbRef = firebase.database().ref().child('text');
dbRef.on('value', snap => bigOne.innerText) = snap.val())
</script>
</body>
</html>
我错过了什么吗?我是新人,所以我可能缺少一小步。
【问题讨论】:
-
这行末尾有一个额外的
)dbRef.on('value', snap => bigOne.innerText) = snap.val())。 -
但作为旁注,我还建议您检查
console.firebase.google.com中Databases下的规则,以确保您确实拥有read/write权限!对于开发,您可以将false更改为true。
标签: javascript html firebase firebase-realtime-database