我正在使用phonegap桌面应用程序(当我在桌面应用程序中单击“创建文件”时,文件会自动生成。)与此项目一起使用atom编辑器和firebase。总结我的项目,这只是某种调查,因此用户将不得不填写一些表格。
我无法将表单详细信息上载到Firebase。我确定Firebase已正确连接,因为我能够从Firebase检索数据并显示在控制台中。但是它无法将表单数据存储到其中。
这是我的html页面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<script type="text/javascript" src="cordova.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<title>AMT Survey</title>
</head>
<body>
<a href="index.html"><img src="img/back.png" style="width:8%;"></a><br>
<form id="amtForm">
<b style="font-size: 27px;">AMT <p></b>
<b class=fs>Screen by: </b><br><input type="text" name="screenby" id="screenby"><br>
<b class=fs>Name of client:</b> <br><input type="text" name="client" id="client"><br>
<b class=fs>Date: </b><br><input type="date" name="date" id="date"><p>
<input type="submit" class="button" value="Submit">
<!--<button (click)="postData(name)">submit</button>-->
</form>
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
<script scr="main.js"></script>
</body>
</html>
这是我的js文件
// Initialize Firebase
(function() {
const config = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
};
firebase.initializeApp(config);
}());
//reference messages collection
var nameRef = firebase.database().reference('name');
// listen for form submit
document.getElementById('amtForm').addEventListener('submit',submitForm);
function submitForm(e){
e.preventDefault();
var name = getInputVal('name');
var client = getInputVal('client');
var date = getInputVal('date');
saveMessage(name,client,date);
}
function getInputVal(id){
return document.getElementById(id).value;
}
function saveMessage(name,client,date){
var newMessageRef = nameRef.push();
newMessageRef.set({
name:name,
client:client,
date:date
});
}
/*
postData(name){
firebase.database().ref().push({name:name});
}
*/
这些代码来自youtube视频教程,他似乎没有遇到像我一样的错误。这是视频https://www.youtube.com/watch?v=PP4Tr0l08NE
我的代码有什么问题吗?还是我的设置错误?还是其他原因?
希望此sreenshot帮助提供屏幕截图,下划线是我在文本框中键入的值。
这表明已读取数据,但是以某种方式它不会进入
firebase FYI:cornova.js脚本不会影响连接。这不是一个错误的错误
您是否将读写权限设置为true?
还要更改此内容://参考消息集合var nameRef = firebase.database()。reference('name');
若要://参考消息集合var nameRef = firebase.database()。ref('name');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句