Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将数据发送到firebase并返回index.html_Javascript_Html_Firebase_Firebase Realtime Database - Fatal编程技术网

Javascript 将数据发送到firebase并返回index.html

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

我正在使用javascript表单将一些数据发送到Firebase数据库,在确认数据已保存后,我需要该页面返回到
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();