微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 带phonegap和firebase的移动应用程序

我正在使用phonegap桌面应用程序(使用我在桌面应用程序中单击创建文件自动生成文件.),使用原子编辑器和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 helpscreenshot下划线是我在文本框中键入的值.这表明数据已被读取,但不知何故它不会进入firebase
仅供参考:cornova.js脚本不会影响连接.这不是一个错误错误

enter image description here

解决方法:

您是否将读写权限设置为true?

也改变这个:
//引用消息集合var nameRef = firebase.database().reference(‘name’);

至:
//引用消息集合var nameRef = firebase.database().ref(‘name’);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐