Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

Can't get firebase to connect to HTML page

$
0
0

I'm working on the front end for a project to display a graph of data collected from sensors. I'm following Net Ninja's youtube series on connecting to firebase, as well as trying many other approaches found online, but nothing I try works. I cannot get data from my firebase test database to display, and also can't display example data from others. I was hoping for a bit of help in what I could have missed.

My index.html is as follows:

<html>
    <head>
        <script src="https://www.gstatic.com/firebasejs/5.0.3/firebase-app.js"></script>
        <script src="https://www.gstatic.com/firebasejs/5.0.3/firebase-firestore.js"></script>
        <script src="https://www.gstatic.com/firebasejs/5.0.3/firebase-database.js"></script>
        <link rel="stylesheet" href="styles.css">
    </head>
    <body>

        <h1>test</h1>

        <div class="content">

            <form id="add-data-form"></form>

            <ul id="data-list"></ul>

        </div>

<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.9.1/firebase-app.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.9.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.9.1/firebase-database.js"></script>

<script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    **FIREBASE DATA**
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  const db = firebase.firestore();
  firebase.analytics();
</script>

        <script src="app.js"></script>
    </body>
</html>

And my app.js is as follows:

const dataList = document.querySelector('#data-list');

// create element & render data
function renderData(doc){
    let li = document.createElement('li');
    let time = document.createElement('span');
    let data = document.createElement('span');

    li.setAttribute('data-id', doc.id);
    time.textContent = doc.data().time;
    data.textContent = doc.data().data;

    li.appendChild(time);
    li.appendChild(data);

    dataList.appendChild(li);
}

// getting data
db.collection('sensorData').get().then(snapshot => {
    snapshot.docs.forEach(doc => {
        renderData(doc);
    });
});

When I launch the index, I only see the "test" heading, no data from the firebase. I have used powershell to initialise the database, that didn't make a difference though. Any help would be greatly appreciated, thank you


Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>