【发布时间】:2019-10-18 17:24:03
【问题描述】:
Firebase 实时数据库中的值未更新。我是 Web 开发的新手,但我知道一点 html。你能检查一下这里有什么问题吗? 对于这个问题,我故意将 Firebase Config 留空。 我尝试使用 Firebase 文档中给出的大部分代码。
<!DOCTYPE html>
<html>
<head>
<title>"Web App"</title>
</head>
<body>
<div class="mainDiv" align="left">
<h1 align="left">"Firebase web page"</h1>
<textarea id="Command" placeholder="ON/OFF" stClyle="text align:left; overflow:auto; border:6px outset #000000;"></textarea>
<button id="Submit" onclick="submitclick()">Click Me!</button>
</div>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/6.1.0/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#config-web-app -->
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "___________________________",
authDomain: "_________.firebaseapp.com",
databaseURL: "https://___________.firebaseio.com",
projectId: "________",
storageBucket: "_________.appspot.com",
messagingSenderId: "________",
appId: "_____________"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var mainTxt= document.getElementById("Command");
var submitbtn = document.getElementById("Submit");
function submitclick()
{
var com = mainTxt.value;
firebase.database().ref().child("username").set(com);
}
</script>
</body>
</html>
【问题讨论】:
-
firebase.dtabase().ref().child(...).set(..)的数据库中有错字。应该是firebase.database().ref().child(....).set(...) -
是的.. 抱歉。我添加了我在此处复制代码的那一行。但这并不能解决问题,它仍然无法正常工作。
-
控制台有错误吗?
-
我主要有 1 个孩子:“用户名”...我也已经设置了网络应用程序。
-
在规则中读写都是真的
标签: html firebase firebase-realtime-database