Last active
December 15, 2017 10:14
-
-
Save abirjameel/1dd0d339bba4bea40c6df10260a3ac5f to your computer and use it in GitHub Desktop.
Converting JSON request received to render as html text
This file contains 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> | |
$(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