parse JSON objects to HTML table

Viewed 49

im developing discord bot for my server and i want to display moderator members data on html page but when i tryimg to fetch data to html its not working

ı want it to look like; CLICK TO SEE IMAGE

my data example:

{
"753145456653238272":{"registrar":71, "totaljoin": 15}, //long numbers = member id.
"781953840642654259":{"registrar":4, "totaljoin": 9},
"826542706083495986":{"registrar":5, "totaljoin": 5}
}

HTML PAGE IS

<table id="report" class="table table-bordered table-striped table-hover js-basic-example dataTable">
        <thead>
            <tr>
                <th>Id</th>
                <th>Total Register</th>
                <th>Total Join</th>           
            </tr>
        </thead>
        <tbody>         
        </tbody>
</table>
<script>
    app.viewReport();      
</script>

AND JAVASCRIPT

viewReport : function() {
               $.ajax({
                url: "http://localhost/api/data/",
                dataType: "json",
                method : 'GET',
                success : function(data){
                 for (var i = 0; i < data.length; i++) {
                    tr = $('<tr/>');
                    tr.append("<td>" + data[i].id+ "</td>");
                    tr.append("<td>" + data[i].registrar+ "</td>");
                    tr.append("<td>" + data[i].totaljoin+ "</td>");  
                    $('#report tbody').append(tr);
                }               
                }           
                /*$.each(data,function(i,item){
                            $('#report tr.odd').remove();
                            $("#report tbody").append(
                                "<tr>"
                                    +"<td>"+item.id+"</td>"
                                    +"<td>"+item.registrar+"</td>"
                                    +"<td>"+item.totaljoin+"</td>"                                                       
                                +"</tr>" )
                            })  
                }*/
    })
    }, 

0 Answers
Related