gpt4 book ai didi

javascript - 页面重定向时没有数据输入 firebase 数据库

转载 作者:行者123 更新时间:2023-12-03 03:16:24 25 4
gpt4 key购买 nike

上面的代码将我重定向到所需的页面,但没有将数据输入数据库。

如果我删除 window.location.href 命令,数据将成功输入数据库。

我想一起完成这两项任务。出路何在?

var firebasep = firebase.database().ref();
var cool = firebasep.child(i.value).set(j.value);
console.log(cool);
firebasep.set(newData, function(error) {
alert("New");
window.location.href="Votingpage.html";
});

最佳答案

您可以使用提到的 promise here确定何时可以安全地将用户重定向到 Votingpage.html

firebasep.set(newData).then(function(data){
alert("New");
window.location.href="Votingpage.html";
}).catch(function(error){
console.log(error);
});

关于javascript - 页面重定向时没有数据输入 firebase 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46755552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com