Kingston_Pendrive/Suli/12.b/Szoftvertesztelés/Órai/2023. 10. 20/ajax.js

25 lines
719 B
JavaScript
Raw Normal View History

2024-11-19 18:04:02 +00:00
const button = document.getElementById("getcucc")
button.addEventListener("click", () =>{
let xhr = new XMLHttpRequest()
xhr.onreadystatechange = () =>{
if (xhr.readyState === 4 && xhr.status === 200){
let adat = JSON.parse(xhr.responseText)
console.log(adat)
let tohtml = ""
for (let user of adat.data){
tohtml += `<h1>${user.first_name}</h1>`
tohtml += `<img src=${user.avatar}><br>`
tohtml += `<h1>${user.email}</h1>`
}
document.getElementById("cucc").innerHTML = tohtml
}
}
xhr.open("GET", "https://reqres.in/api/users?page=2")
xhr.send()
})