下面是我的javascript函数,当我使用页面重定向代码(window.location.href
)时,它不会更新firebase。但是,当window.location.href
被删除时,它正在正确更新firebase。
<script type="text/JavaScript">
function bookappnt() {
var appname = document.getElementById("app-name").value;
var ref = new Firebase("https://dermaenbgtt1233.firebaseio.com/");
var usersRef = ref.child("Appointment-Details");
usersRef.push({
applicationname: appname
});
window.location.href = "http://www.example.com";
}
</script>
<input type="text" id="app-name" class="user" placeholder="Name">
<input type="submit" value="Book appointment" onclick ="bookappnt()">
答案 0 :(得分:0)
问题已通过.then()
解决。谢谢大家的帮助!
<script type="text/JavaScript">
function bookappnt() {
var appname = document.getElementById("app-name").value;
var ref = new Firebase("https://dermaenbgtt1233.firebaseio.com/");
var usersRef = ref.child("Appointment-Details");
usersRef.push({
applicationname: appname
}).then( user => {
window.location.href = "http://www.example.com";
});
}
</script>