JSFiddle - React, Tailwind, and code Playground
by lavisha99
HTML
<head>
</head>
JavaScript
/*
NARRATIVE: The jsonplaceholder.typicode.com website offers a service that we can use for testing AJAX applications.
You are asked to write a program that requests information about users given their IDs and displays the users names.
The URL of this service is: https://jsonplaceholder.typicode.com/users/ .
To get information about a user with ID 1, you need to request the URL https://jsonplaceholder.typicode.com/users/1
Note how the number 1 is appended to the end of the URL.
Try the above URL in your browser with multiple IDs to explore the data.
You need to test your program with the user IDs: 1, 2, 3, 4, and 5
*/
var requestURL = 'https://jsonplaceholder.typicode.com/users/';
var users = [1,2,3,4,5];
for(let i=0; i<users.length; i++){
let user= users[i];
let url= requestURL + user;
let request = new XMLHttpRequest();
request.responseType='json';
request.onload = function () {
user= request.response;
console.log(user.id, user.name);
}
request.open('GET', url);
request.send();
}