为什么我的数据没有被存储到我的firebase实时数据库?

l7wslrjt  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(119)

我正在尝试为一个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")
}
zc0qhyus

zc0qhyus1#

我觉得emailphone-numberfirstName,和lastName<input>元素,因为你想检索它们的值,你必须使用value属性,否则你会得到实际的HTML代码,更多细节见下文。

var firstName = document.getElementById("firstName");
var lastName = document.getElementById("lastName");

firstName.addEventListener("input", function () {
  console.log(firstName);
});

lastName.addEventListener("input", function () {
  console.log(this.value);
});
<input id="firstName" />
<input id="lastName" />

可能(高度猜测),Firebase不会存储HTML代码,所以它切换到null

相关问题