elin-r
8/15/2017 - 9:40 PM

Javascript API + Parse JSON

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

<script>
var xhr = new XMLHttpRequest();

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

console.log(xhr.response);

var obj = JSON.parse(xhr.response);
document.getElementById("demo").innerHTML = obj.title + "<br/> " + obj.body;
</script>