I am accepting data into a variable and I want the variable to be a part of a URL to point to a location in the Firebase db from where I want to retrieve the data.
Here is my code:
function Call()
{
var dbref=new Firebase("https://dataretrievaltest-28983.firebaseio.com/EmployeeDB/EInfo").orderByKey();
var login=localStorage.getItem("Email");
console.log("Passed Email"+login);
dbref
.once("value")
.then
(
function(snapshot)
{
snapshot.forEach
(
function(childsnapshot)
{
var data = childsnapshot.val();
var emailval=data.Email;
if(login==emailval)
{
console.log(data.EID);
Eidval=data.EID;
}
}
);
}
);
var dsRef=new Firebase("https://dataretrievaltest-28983.firebaseio.com/EmployeeDB/EDetail/EmployeeDB/EDetail/"+Eidval);
dsRef
.once("value")
.then
(
function(snapshot)
{
//console.log(snapshot.val());
snapshot.forEach
(
function(childsnapshot)
{
var data = childsnapshot.val();
console.log(data);
}
);
}
);
}
Above code is not working and appending /EDetail/"+Eidval
is not producing any o/p
Eidval
is defined as a global variable:
<body>
<input type="button" value="Pull" id="btpull" onclick="Call()">
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script src="https://cdn.firebase.com/v0/firebase-simple-login.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.6/firebase.js"></script>
<script>
var Eidval=0;
var config = {
apiKey: "AIzaSyA2LEx_3C0qPI75AexMPhCfZCxnVV-MVbU",
authDomain: "dataretrievaltest-28983.firebaseapp.com",
databaseURL: "https://dataretrievaltest-28983.firebaseio.com",
storageBucket: "dataretrievaltest-28983.appspot.com",
messagingSenderId: "572246196580"
};
firebase.initializeApp(config);
</script>
Output:
Passed Emailchris@page.com Phase1work.html:51 153