0

I have data downloaded from firebase DB and the data is fine but when this data is loaded into HTML all table TD shows undefined, not able to understand why been check a whole lot of codes not able to understand whats wrong here.

Thank You

var registration = firebase.database().ref("REGISTRATION")

dataRef = firebase.database().ref().child("REGISTRATION");

dataRef.on("value", rData);

function rData(data){

    console.log(data.val());
    var gData = data.val();
        for (gDatarow in gData)
    {
    alert(email);
        var email = gDatarow.email;
        var name = gDatarow.name;
        var gender = gDatarow.gender;
        var date = gDatarow.date;
        var phone = gDatarow.phone;
        var state = gDatarow.state;
        var school = gDatarow.school;
        var clas = gDatarow.clas;
        var classname = gDatarow.classname;
        $("#reData").append("<tr><td>" + email + "</td></td>" + name + "</td><td>" + gender + "</td></td>" + date + "</td><td>" + phone + "</td></td>" + state + "</td><td>" + school + "</td></td>" + clas + "</td><td>" + classname + "</td></tr>");    

}
}

enter image description here

Huud Rych
  • 21
  • 5
  • What is the console output of console.log(data.val())? – fhossfel Sep 17 '17 at 11:52
  • And ist there any good reason not to use a "for (gDataRow in gData)"? – fhossfel Sep 17 '17 at 11:57
  • Sorry I had uploaded an image as well but not showing...you mean a for loop ? – Huud Rych Sep 17 '17 at 12:10
  • Yes. Seems simpler. – fhossfel Sep 17 '17 at 12:14
  • Still getting undefined, this is the image of data in the console: https://i.stack.imgur.com/K1lXT.png – Huud Rych Sep 17 '17 at 12:37
  • YOu have a line in there: `console.log(data.val());`. So go into the console (F12 in a browser) and take a look - what is it outputting? – Nick.Mc Sep 17 '17 at 12:40
  • This is my output in the console KEG8tn1-nEDfZLAwAD : {Birthday: "10-dec-1984", Class: "X", Classname: "Science", Email: "khlkhljk@yahoo.com", Gender: "MALE", …} -KuEGGyZYX9nu07i3Wp0 : {Birthday: "10-dec-1984", Class: "Central School", Classname: "Science", Email: "iiiiiii@yahoo.com", Gender: "FEMALE", …} -KuEXumI_Z3tY3ytA_90 : {Birthday: "23432432423", Class: "OnlineLearningPortal", Classname: "Tomato", Email: "yyyyyy@yahoo.com", Gender: "FEMALE", …} __proto__ : Object – Huud Rych Sep 17 '17 at 12:44
  • Have you noticed that your field names in the code all start with lowercase letters but the JSON you posted has Email, Birthday etc. They start with a capital letter. – fhossfel Sep 17 '17 at 16:45
  • Thanks, changed all to lower case still shows as undefined in html... – Huud Rych Sep 17 '17 at 20:31
  • I did a bit of debugging from within firefox and there seems to be some issue in variables email, name etc or childnodes,...as fire fox shows data in gData and gDatarow in the debugger... – Huud Rych Sep 17 '17 at 23:28
  • Possible duplicate of [Firebase data returning an UNDEFINED value even though it has content](https://stackoverflow.com/questions/45560959/firebase-data-returning-an-undefined-value-even-though-it-has-content) – bummi Sep 18 '17 at 10:53
  • 1
    Appreciate it @bummi thanks a lot... – Huud Rych Sep 18 '17 at 11:57

1 Answers1

0

This is what worked in my case :

dataRef.on("child_added", function(data) {
    var rData = data.val();
$("#reData").append("<tr><td>" + rData.email + "</td><td>" + rData.name + "</td><td>" + rData.gender + "</td><td>" + rData.birthdate + "</td><td>" + rData.phone + "</td><td>" + rData.state + "</td><td>" + rData.school + "</td><td>" + rData.class + "</td><td>" + rData.classname + "</td></tr>");
});

Thanks to all for their time.

Huud Rych
  • 21
  • 5