Skip to content

Instantly share code, notes, and snippets.

@abirjameel
Last active December 15, 2017 10:14
Show Gist options
  • Save abirjameel/1dd0d339bba4bea40c6df10260a3ac5f to your computer and use it in GitHub Desktop.
Save abirjameel/1dd0d339bba4bea40c6df10260a3ac5f to your computer and use it in GitHub Desktop.
Converting JSON request received to render as html text
<script>
$(document).ready(function() {
$("#getMessage").on("click", function() {
   $.getJSON("/json/cats.json", function(json) {
var html = "";
// Only change code below this line.
json.forEach(function(val) {
var keys = Object.keys(val);
html += "<div class = 'cat'>";
keys.forEach(function(key) {
html += "<strong>" + key + "</strong>: " + val[key] + "<br>";
});
html += "</div><br>";
});
// Only change code above this line.
     $(".message").html(html);
   });
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment