ajout bouton
This commit is contained in:
		
							parent
							
								
									c10b0d39ce
								
							
						
					
					
						commit
						00b04b0d81
					
				
					 2 changed files with 31 additions and 2 deletions
				
			
		|  | @ -20,5 +20,7 @@ | ||||||
| 
 | 
 | ||||||
|         <div id="personne"></div> |         <div id="personne"></div> | ||||||
|     </section>     |     </section>     | ||||||
|  | 
 | ||||||
|  |     <button id = "page2">page suivante </button> | ||||||
| </body> | </body> | ||||||
| </html> | </html> | ||||||
							
								
								
									
										31
									
								
								script.js
									
										
									
									
									
								
							
							
						
						
									
										31
									
								
								script.js
									
										
									
									
									
								
							|  | @ -4,10 +4,9 @@ const IDENTIFIANT = document.getElementById('identifiant'); | ||||||
| const EMAIL = document.getElementById('email'); | const EMAIL = document.getElementById('email'); | ||||||
| const AVATAR = document.getElementById('avatar'); | const AVATAR = document.getElementById('avatar'); | ||||||
| const MEMBER = document.getElementById('personne'); | const MEMBER = document.getElementById('personne'); | ||||||
|  | const BUTTON = document.getElementById ('page2'); | ||||||
| 
 | 
 | ||||||
| const API_URL = "https://reqres.in/api/users?page=1"; | const API_URL = "https://reqres.in/api/users?page=1"; | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| fetch(API_URL) | fetch(API_URL) | ||||||
| .then((response) => { | .then((response) => { | ||||||
|     console.log(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 => { | .catch(err => { | ||||||
|     console.error(err); |     console.error(err); | ||||||
|  | }) | ||||||
| }); | }); | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Blandine Bajard
						Blandine Bajard