ajout bouton
This commit is contained in:
parent
c10b0d39ce
commit
00b04b0d81
@ -20,5 +20,7 @@
|
||||
|
||||
<div id="personne"></div>
|
||||
</section>
|
||||
|
||||
<button id = "page2">page suivante </button>
|
||||
</body>
|
||||
</html>
|
31
script.js
31
script.js
@ -4,10 +4,9 @@ const IDENTIFIANT = document.getElementById('identifiant');
|
||||
const EMAIL = document.getElementById('email');
|
||||
const AVATAR = document.getElementById('avatar');
|
||||
const MEMBER = document.getElementById('personne');
|
||||
const BUTTON = document.getElementById ('page2');
|
||||
|
||||
const API_URL = "https://reqres.in/api/users?page=1";
|
||||
|
||||
|
||||
fetch(API_URL)
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
@ -38,6 +37,33 @@ fetch(API_URL)
|
||||
|
||||
}
|
||||
|
||||
BUTTON.addEventListener('click', ()=>{
|
||||
const API_PAGE2 = "https://reqres.in/api/users?page=2";
|
||||
fetch(API_PAGE2)
|
||||
.then((response2) => {
|
||||
console.log(response2);
|
||||
return response2.json()
|
||||
})
|
||||
.then(responsFormat2 => {
|
||||
console.log(responsFormat2);
|
||||
for(let index = 0; index <6; index++){
|
||||
console.log(responsFormat2.data[index]);
|
||||
const PERSONNE = responsFormat2.data[index];
|
||||
console.log(PERSONNE);
|
||||
|
||||
MEMBER.innerHTML +=`
|
||||
<div>
|
||||
<p>${PERSONNE.last_name}</p>
|
||||
<p>${PERSONNE.first_name}</p>
|
||||
<p>${PERSONNE.id}</p>
|
||||
<p>${PERSONNE.email}</p>
|
||||
<img src="${PERSONNE.avatar}" alt="">
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
)
|
||||
@ -46,4 +72,5 @@ fetch(API_URL)
|
||||
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
})
|
||||
});
|
Loading…
Reference in New Issue
Block a user