首页 > 解决方案 > 无法写入 Firebase,没有错误

问题描述

出于某种原因,每次我尝试写入我的 Firebase 数据库时,数据库中都不会出现任何内容,也不会引发任何错误。用户创建帐户后,我检查用户是否在数据库中,如果没有,则将他们带到设置页面,在那里他们选择显示名称和帐户类型(学生或教师)。然后我将它输入数据库。我从数据库读取没有问题,我可以从我的 python 后端写入它,但我无法从 javascript 前端成功写入任何内容。这是我的代码

              <script>
              function teacherType (){
                  var uid = firebase.auth().currentUser.uid;
            var database = firebase.database();
                var name = document.getElementById("displayName").value;
                 firebase.database().ref('/users/teachers/' + uid).set({"displayName":name}).then(window.location.replace("/teacherDashboard"));

              };
              function studentType (){
                  var uid = firebase.auth().currentUser.uid;
            var database = firebase.database();
                var name = document.getElementById("displayName").value;
                 firebase.database().ref('/users/students/' + uid).set({"displayName":name}).then(window.location.replace("/studentDashboard"));
              };
          </script>
          <section id="main">
          <div class="content-section text-center" id="accountType">
                        <p>Add your Display Name Below</p>
     <input id="displayName"/>
              <p>Are you a student or a teacher?</p>
              <span>                <a onclick="studentType()" href="#" 
        class="btn btn-default btn-lg"><font face="sans-serif">Student</font>
                    </a></span>
<span>
<a href="#" class="btn btn-default btn-lg"><font face="sans-serif" onclick="teacherType()">Teacher</font>
              </a></span>
              </div>


          </section>

抱歉格式不好。我测试了 uid 和 name 已定义,所以我认为这不是问题。然而,firebase 数据库中没有出现任何内容,并且该站点转到/teacherDashboard/studentDashboard相应地转到。我不确定我错过了什么......

标签: javascriptdatabasefirebasefirebase-realtime-database

解决方案


推荐阅读