Javascript 将数据发送到firebase并返回index.html
我正在使用javascript表单将一些数据发送到Firebase数据库,在确认数据已保存后,我需要该页面返回到Javascript 将数据发送到firebase并返回index.html,javascript,html,firebase,firebase-realtime-database,Javascript,Html,Firebase,Firebase Realtime Database,我正在使用javascript表单将一些数据发送到Firebase数据库,在确认数据已保存后,我需要该页面返回到index.html,以下是我得到的: JavaScript HTML输入 您需要使用该方法返回的。例如: rootRef.child(name).child("model").set(model) .then(function() { console.log('Synchronization succeeded'); // Return to
index.html
,以下是我得到的:
JavaScript
HTML输入
您需要使用该方法返回的。例如:
rootRef.child(name).child("model").set(model)
.then(function() {
console.log('Synchronization succeeded');
// Return to index.html here...
})
.catch(function(error) {
console.log('Synchronization failed');
});
在你的btnAsset
监听器的末尾添加此内容也是一个好主意(有关更多详细信息,请参阅Jon Jacques评论):
此外,您可能需要在btn侦听器的末尾添加一个
e.preventDefault()
,因为按钮的默认行为是提交表单。如果没有表单提交,页面将重新加载。根据OP对这个问题的描述,我可以想象这里也会发生同样的事情。@JonJaques真是太棒了!答案更新,感谢您的反馈。
<input type="text" class="form-control" id="inputName" placeholder="Asset Name">
<input type="text" class="form-control" id="inputResp" placeholder="Owner">
rootRef.child(name).child("model").set(model)
.then(function() {
console.log('Synchronization succeeded');
// Return to index.html here...
})
.catch(function(error) {
console.log('Synchronization failed');
});
e.preventDefault();