数据不会存储并从 Firestore 数据库中检索

时间:2021-02-13 18:37:37

标签: javascript firebase firebase-realtime-database

这是我的 html 代码,我不知道我在哪里做错了,请检查并帮助我。控制台中没有检测到错误,只有值没有得到,甚至没有存储在数据库中

<!DOCTYPE html>

<head>
  <script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-database.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-firestore.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-storage.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-functions.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-messaging.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-analytics.js"></script>
  <script src="abc.js"></script>
</head>

<body>
  <form method="GET">
    <input id="restaurant_address" placeholder="Restaurant Address" />

    <input id="restaurant_pass" placeholder="Restaurant pass" />
    <button id="myBtn"> Submit </button>
    <button id="myBtn2"> view </button>

  </form>

  <script>
    document.getElementById("myBtn").addEventListener("click", function(e) {
      e.stopPropagation();

      var userdetails = {
        address: document.getElementById("restaurant_address").value,
        pass: document.getElementById("restaurant_address").value

      }
      // Create a new post reference with an auto-generated id
      var postListRef = firebase.database().ref('users');
      alert(postListRef);
      var newPostRef = postListRef.push();
      alert(newPostRef);
      newPostRef.set(userdetails);
    });

    document.getElementById("myBtn2").addEventListener("click", function(e) {
      alert("enterd");

      firebase.database().ref('abc').on('value', function(snapshot) {
        alert("db");
        console.log(snapshot);
        if (snapshot.exists()) {
          alert("if");
          snapshot.forEach(function(data) {
            var val = data.val();
            console.log(val);
          });
          s
        } else {
          alert("errrrrrror");
        }
      });
    });
  </script>
</body>

</html>

0 个答案:

没有答案