我正在使用javascript表单向 Firebase数据库发送一些数据,在我确认数据已保存后,我需要该页面返回index.html
,此处为'我得到了什么:
btnAsset.addEventListener('click', e =>{
const name = inputName.value;
const model = inputModel.value;
var rootRef = firebase.database().ref().child("Assets");
rootRef.child(name).child("model").set(model);
});
<input type="text" class="form-control" id="inputName" placeholder="Asset Name">
<input type="text" class="form-control" id="inputResp" placeholder="Owner">
答案 0 :(得分:2)
您需要使用firebase.Promise
方法返回的Reference.set(value)
。例如:
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的评论):
e.preventDefault();