// In the index.html file there is a button. When the button is
// clicked kick off an HTTP GET request to the following URL:
//
// https://jsonplaceholder.typicode.com/posts
//
// The response text will be a JSON-encoded array of objects. Inspect
// the response using the browser debugger and then insert the objects
// into the DOM. Each object in the response should be used to create
// a new <li> element in the existing <ul> container with the id of "data".
// Display the post title within the <li> element
//
// BONUS #1:
//
// Clicking one of the <li> elements should display all information
// about the clicked post's author (user) in the <ul> with the ID of "details".
// Hint:
// make another HTTP request to
// https://jsonplaceholder.typicode.com/users/{N}
// where {N} is the post user_id
//
//
// Your code here.
var loadbutton = document.querySelector('button');
var getdata = document.getElementById('data');
//var ui = document.createElement('u1');
//ui.appendChild(document.createElement('li'));
var req = new XMLHttpRequest();
var url = "https://jsonplaceholder.typicode.com/posts";
req.open("GET",url,true);
req.setRequestHeader("Accept","application/json");
req.send(null);
loadbutton.addEventListener("click",function(e){
console.log(req.responseText);
var data = JSON.parse(req.responseText);
//Add it to li
var
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.