A simple JSON renderer designed to parse JSON from an external URL and display selected elements in a basic HTML table. I don't use jQuery often, but this made it simple, fast, and easy for others to work with.
Last active
November 21, 2022 06:45
-
-
Save alexmwalker/98cd5ff0f82cd536f706c212a39b3a51 to your computer and use it in GitHub Desktop.
Simple JSON viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h1>Loading latest data from Raisely</h1> | |
| <table class="ladder"> | |
| <thead><tr><td> </td><td>Name: </td><td>Total</td></tr></thead> | |
| <tbody id = "stage"> | |
| <!-- The Raisely JSON data gets injected in here --> | |
| </tbody> | |
| </table> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var url = 'https://api.raisely.com/v3/profiles?campaign=447025f0-0e01-11ed-8e4d-c90543f52ff7&limit=6&offset=0&order=desc&q=&sort=total&type='; | |
| $(document).ready(function () { | |
| $.getJSON(url, function (ladder) { | |
| $.each(ladder.data, function(index, element) { | |
| //alert(element.name); | |
| $("#stage").append("<tr>"); // open new row | |
| $("#stage").append("<td class='photoUrl'> <img src='" + element.photoUrl + "' /></td>"); | |
| $("#stage").append("<td> " + element.name + "</td>"); | |
| $("#stage").append("<td> $" + element.total + "</td>"); | |
| $("#stage").append("</tr>"); // close new row | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-compat/3.0.0-alpha1/jquery.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body { | |
| margin: 2rem; | |
| } | |
| table { | |
| background-color: #eee; | |
| border-collapse: collapse; | |
| width: 100%; | |
| margin: 0 auto; | |
| } | |
| table thead td { | |
| background: #444; | |
| color: #8; | |
| } | |
| table td { | |
| outline: 1px #ddd solid; | |
| padding: 5px; | |
| } | |
| .photoUrl { | |
| width: 40px; | |
| } | |
| .photoUrl img { | |
| width: 100%; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment