I'm learning Javascript and today I learned AJAX. I am using Vanilla JS and simple AJAX. My task is to get the object of a user from the url by user input - ID. I've tried the .data and still won't work. Any help would be appriciated!
async function display() {
try {
let id = +userID.value;
const url = `https://jsonplaceholder.typicode.com/users/${id}`;
const response = await fetch(url);
const rootObject = await response.json();
const users = rootObject.data;
getUser(users);
} catch (err) {
alert(err.message);
}
}
display()
I have another function - getusers(users) that currently is empty because it isn't working. How can I access the object only from the url?
console.log(rootObject)to see the actual structure of the object.response.datais something you normally see with Axios which isn't what you're using.getUserfunction works