I'd like pull a value via firebase api and make it a global variable, so that I can refer to it else where in the code
I'd like for the below code to work where I pull a value from firebase and can use it outside of the function (http://jsfiddle.net/chrisguzman/jb4qLxtb/)
var ref = new Firebase('https://helloworldtest.firebaseIO.com/');
ref.on('value', function (snapshot) {
var Variable = snapshot.child("text").val();
return Variable;
});
alert(Variable);
I've tried defining it with var below with no luck (http://jsfiddle.net/chrisguzman/jb4qLxtb/1/)
var ref = new Firebase('https://helloworldtest.firebaseIO.com/');
var MyVariable = ref.on('value', function (snapshot) {
var Variable = snapshot.child("text").val();
return Variable;
});
alert(MyVariable);
I've also tried to define it as a function with no luck: http://jsfiddle.net/chrisguzman/jb4qLxtb/2/
var ref = new Firebase('https://helloworldtest.firebaseIO.com/');
function myFunction() { ref.on('value', function (snapshot) {
var Variable = snapshot.child("text").val();
return Variable;
});};
alert(myFunction());