我正在尝试创建一个简单的应用程序以添加到 Firebase 数据库。
写入温度,然后将其与时间戳一起存储在数据库中。但由于某种原因,它不会工作。我尝试了多种不同的方法并检查了 Firebase 网站上的所有文档,但没有任何效果。任何帮助将不胜感激。谢谢
https://glitch.com/edit/#!/lcjs
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://www.gstatic.com/firebasejs/7.3.0/firebase-app.js"></script>
<title>Write to firebase</title>
</head>
<body>
<h1>Current Tempature</h1>
Tempature <input type="text" id="UserData"/>
<input type="button" id="Submit" onclick="formSubmission()" value="Submit"/>
<p id="done">
</p>
<script src="script.js"></script>
</body>
</html>
脚本.JS
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyDvLIcv7nEIbfnz99mhoLi8UizaJcZxHLM",
authDomain: "lcls-332a0.firebaseapp.com",
databaseURL: "https://lcls-332a0.firebaseio.com",
projectId: "lcls-332a0",
storageBucket: "lcls-332a0.appspot.com",
messagingSenderId: "604417688851",
appId: "1:604417688851:web:63eb89e29b81cd1a8546e6",
measurementId: "G-N2TVNX43T6"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
function formSubmission(){
document.getElementById("done").innerHTML = "Clicked";
var today = new Date();
var timestamp = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds() + " " + today.getDate() + "/" + today.getMonth() + "/" + today.getFullYear();
var myDBConn = firebase.database().ref();
document.getElementById("done").innerHTML = "Done";
var TempBranch = myDBConn.child("MyTempatures");
var currentTemp = document.getElementbyID("UserData");
TempBranch.push({ Tempature: parseInt[currentTemp.value], Time: timestamp });
document.getElementById("done").innerHTML =
"Your result has been successfully added!";
}