elin-r
8/16/2017 - 6:18 AM

Javascript API + Parse JSON Object

<html>
<div id="demo">
</div>
</html>

<script>
var xhr = new XMLHttpRequest();

xhr.open("GET", "https://jsonplaceholder.typicode.com/posts/", false);
xhr.send();

console.log(xhr.response);

var obj = JSON.parse(xhr.response);

Object.keys(obj).forEach(function(i) {
document.getElementById("demo").innerHTML += obj[i].title + "<br/>" + obj[i].body + "<br/><br/>";
});

</script>