-1

when i am trying to print data in html its show error.

i want print atlets details like first name, last name etc.

Please help, Thanks in advance!

https://uhsaa.org/stats/leaders.json

$(document).ready(function(e) {
   var dmJSON = "https://uhsaa.org/stats/leaders.json?callback=?";
    $.getJSON( dmJSON, function(data) {
       $.each(data.Leaders.Athletes, function(i, f) {
          var tblRow = "<tr>" + "<td data-label='ID'>" + f.id + "</td>" + "<td  data-label='User Name'>" + f.user.username + "</td>" + "<td  data-label='URL'>"+ f.url + "</td>" +"</tr>"
           $(tblRow).appendTo("#entrydata tbody");
     });

    });
});
1
  • this is dummy table row var tblRow = "<tr>" + "<td data-label='ID'>" + f.id + "</td>" + "<td data-label='User Name'>" + f.user.username + "</td>" + "<td data-label='URL'>"+ f.url + "</td>" +"</tr>" $(tblRow).appendTo("#entrydata tbody"); Commented Aug 22, 2018 at 18:40

1 Answer 1

1

You could try to generate the HTML then assign it to the table
Hope this helps

$(document).ready(function(e) {
    var dmJSON = "https://cors.io/?https://uhsaa.org/stats/leaders.json";
    htmlBuilder = "";
    $.getJSON( dmJSON, function(data) {
       for(var i=0; i<data.Leaders.Athletes.length; i++){  
       htmlBuilder += "<tr>";
       htmlBuilder += "<td>" + data.Leaders.Athletes[i].Athlete.AthleteID + "</td>";
       htmlBuilder += "<td>" + data.Leaders.Athletes[i].Athlete.FirstName + "</td>";
       htmlBuilder += "<td>" + data.Leaders.Athletes[i].Athlete.Position + "</td>";
       htmlBuilder += "<td>" + data.Leaders.Athletes[i].Athlete.School + "</td>";
       htmlBuilder += "</tr>";
       }
       $("#entrydata").html(htmlBuilder);
     });
});
td, tr, table {
border: 1px solid black;
}
<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
  
<table style="border 1px" id="entrydata">
</table>

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.