db.collection("chatroom").where("who", "array-contains-any", [Myuid, Selleruid]).get().then((result) => {
db.collection('chatroom').add(data)
window.location.href = "/chat.html"
})
这是我将聊天室数据库添加到 Firebase 服务器的代码的一部分。它不起作用,但是当我删除 window.location.href = "/chat.html" 时,它可以添加数据。我不明白为什么删除它后它会起作用,以及为什么它不适用于那个窗口 ~ 行。
调用add()
启动异步写入操作,该操作发生在后台(以防止阻塞浏览器)。但是,您的window.location.href = "/chat.html"
语句会立即运行,因此写入操作在完成之前被中止。
要解决此问题,您需要等待写入操作完成后再离开:
db.collection('chatroom').add(data).then(() => {
window.location.href = "/chat.html"
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句