javascript - 无法写入 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
相应地转到。我不确定我错过了什么......
解决方案
推荐阅读
- c - C 中具有严格别名和严格对齐的面向对象模式的最佳实践
- swift - 如何使用 LinkPresentation 在 SwiftUI 中获取链接元数据?
- javascript - 使用 HTML 和 JavaScript 的 WebGL 全屏按钮?
- javascript - 如何在 mocha.js(或其他库)中修改测试结果的输出
- python - Matplotlib colorbars 多个 plt.imshow 图
- php - 如何修复此注册系统?
- r - 更改多个文件名
- javascript - 按键获取 JSON 对象的路径?
- python - 将数据框与字典合并
- python - cv2.findContours + cv2.contourArea 意外结果