samedi 25 juin 2016

Trouble getting data from Firebase database Node.js/JavaScript


Good morning everyone I'm having a little trouble with Firebase as a new user. In my previous question I asked how I could use my express server making API calls to pass that data retrieved into my firebase database and I was able to make it work! However, now I want to take that data from my database and use it to populate my DOM on the client side.

So we're clear this is how the work flow got my app goes:

  1. Make an AJAX request from my client to my express app app.jssending a small data object {search: search} where the value for search is captured in a form on the client. (works)
  2. Take that data object and make another AJAX request to the third party API, which returns another data object. (works)
  3. Take that response object from the third party API and send that to my database. (works)
  4. A script client-side pulls information from my database to populate the DOM. (not working)

Looking at the myriad of tutorials is tough and I'm following the guides I find exactly using some fine copy pasta, but I'm still stuck.

Here is the client side script firebaseData.js that I'm using to retrieve data from my database, I'm trying to get all the data at the endpoint [my database url]/user:

$(document).ready(function() {
  // create object instance of my Firebase database
  var myDBReference = new Firebase([my database url]);  

  console.log(myDBReference.child("user"))

});

And it returns this in the console client-side:

X {k: Ji, path: P, n: Ce, pc: false, then: undefined…}

And that's all I've been able to get so far. Below is my index.html where I link to firebase it's cdn and a bunch of other stuff I was just told to include in my project:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="main.css">

</head>
<body>
<div id="top">
    <h1>Just Trying to Make a Halo App</h1>
    <form id="searchForm">
        <input id="searchField" type="text"></input>
        <input id="searchButton" type="submit" value="search"></input>
    </form>
</div>

<div id="imageContainer">
    <img id="emblem">
    <img id="spartan">
</div>

<div id="dataContainer">
    <h2></h2>
    <p></p>
</div>


<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "[my key value]",
    authDomain: "[authDomain value]",
    databaseURL: "[databaseURL value]",
    storageBucket: "[storageBucket value",
  };
  firebase.initializeApp(config);
</script>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script type="text/javascript" src="request.js"></script>
<script type="text/javascript" src="firebaseData.js"></script>
</body>
</html>

In actuality the var config object has all the correct information generated from the firebase console- I wish that's all I would need to fix this! Please let me know if you require any more information I'd be happy to provide it and thanks for taking the time to check out my question.

Happy Saturday!


Aucun commentaire:

Enregistrer un commentaire