0

I have managed to submit to firebase. I cant work out how to retrieve data from it though.

JavaScript:

 <input type="submit" onclick=getUsers() value="Get Users"> function getUsers(){ curl 'https://my-cool-project-f0ee8.firebaseio.com/users/jack/name.json?print=pretty' } 

I'm obviously doing something a little stupid. How do I use this curl command and also what do I put instead of the name Jack? is it the users email?

apologies if a dumb question but I am a newbie to firebase

2
  • tried docs : firebase.com/docs/web/guide/retrieving-data.html ? Commented Aug 26, 2016 at 9:47
  • yes but these are the old docs anyway and i couldnt make sense of where to use the curl command Commented Aug 26, 2016 at 9:55

2 Answers 2

2

To retrieve data from firebase, all you have to do is setup a listener on the node that you want to get data from.

var valueRef = firebase.database().ref('users/' + userName); valueRef .on('value', function(snapshot) { processInfo(snapshot.val()); }); 

snapshot.val() will give you a json of the contents on that node. Then you can parse it as you wish.

For more details go to: https://firebase.google.com/docs/database/web/retrieve-data

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

Comments

1

Curl is not a Javascript function or command, it is a bash command that you can use to perform HTTP requests. Where you find documentation talk about curl, it is just an example that you can test within your terminal but Javascript doesn't use cUrl.

If you want to connect to firebase you must use firebase SDK and follow documentation or TsiTMC answer.

if you want to make request manually, you can do Javascript requests like that:

var xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", 'https://my-cool-project-f0ee8.firebaseio.com/users/jack/name.json?print=pretty', false ); // false for synchronous request xmlHttp.send( null ); console.log(xmlHttp.responseText); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.