1

I am creating a two page web based app. Page 1 allows the user to enter a first name, last name, and message and adds it to the firebase DB using push(). I have gotten this to work perfectly.

On page 2 I want it to display all the messages. Ideally, I want to be able to add search parameters for names, but I'll start at the bottom of the mountain and work my way up. My problem is that everytime I use a callback the browser displays "[object Object]" as opposed to any useful information.

I've been playing around with it and searching for answers for a couple hours with no luck. Any help would be greatly appreciated.

<script type="text/javascript">
    var messageRef = new Firebase("https://x.firebaseio.com/messages/");


    messageRef.on('value', function(snapshot) {
    var message = snapshot.val();
        displayMessage(message);
    });

    function displayMessage(name){
        document.getElementById("content").innerHTML = name;
    }
</script>
2
  • you need to stringyfy the object (just to see what you are getting back), then once you know what you are receiving, stop stringifying it and get the properties that you want from the object. Commented Nov 3, 2014 at 20:18
  • I guess the biggest problem is that I have one list for messages, and the push() method assigns them a unique id like -J_rOY12RaccVE_9d413. So the Object tree is actually like messages.J_rOY12RaccVE_9d413.messagetext. I just want to be able to display all the mssages for all the unique ids Commented Nov 3, 2014 at 20:49

1 Answer 1

4

This line

var message = snapshot.val();

assigns message to snapshot witch is object. It should be something like

var message = snapshot.val().messageText;

depending on what key you have used to store your message.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.