我正在尝试为一个Web应用程序创建一个注册页面。这将把数据发送到firebase数据库。我已经阅读了官方的firebase文档,并按照说明写数据。但什么也不会写。在我的数据库控制台中,它说的都是null,而不是我的数据。我没有收到控制台错误。
<button id="signUpButton" onclick="confirmData()">Sign Up!</button>
<script type="module" src="/backend/database.js"></script>
//import and initialize database
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-app.js";
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-database.js";
const firebaseConfig = {
apiKey: "AIzaSyDJdI7Sgr7ZGo3Do6NVswgs1UvjVcQUZbs",
authDomain: "bakerstoolbox-9ca91.firebaseapp.com",
databaseURL: "https://bakerstoolbox-9ca91-default-rtdb.firebaseio.com",
projectId: "bakerstoolbox-9ca91",
storageBucket: "bakerstoolbox-9ca91.appspot.com",
messagingSenderId: "175444196196",
appId: "1:175444196196:web:f6314c643c71315b5f1871"
};
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
//get user sign up data
var email = document.getElementById("email");
var phone = document.getElementById("phone-number");
var firstName = document.getElementById("firstName");
var lastName = document.getElementById("lastName");
//button functions
const signUpButton = document.getElementById("signUpButton");
signUpButton.addEventListener("click", signUpNewUser);
//sign up a new user
function signUpNewUser(){
set(ref(database, 'users/'), {
userEmail : email,
userPhoneNum : phone,
userFirstName : firstName,
userLastName : lastName
});
console.log("DEBUGGING")
}
1条答案
按热度按时间zc0qhyus1#
我觉得
email
,phone-number
,firstName
,和lastName
是<input>
元素,因为你想检索它们的值,你必须使用value
属性,否则你会得到实际的HTML代码,更多细节见下文。可能(高度猜测),Firebase不会存储HTML代码,所以它切换到
null
。