Skip to content

Instantly share code, notes, and snippets.

@Ifmr24
Created September 18, 2018 06:24
Show Gist options
  • Select an option

  • Save Ifmr24/0df44a2a7dd1ac7248836e53d5c0511c to your computer and use it in GitHub Desktop.

Select an option

Save Ifmr24/0df44a2a7dd1ac7248836e53d5c0511c to your computer and use it in GitHub Desktop.
JS Leer API JSON 2
document.querySelector('#boton').addEventListener('click', function(){
traer()
});
function traer(){
fetch('https://randomuser.me/api')
.then( res => res.json())
.then( data => {
console.log(data.results['0'])
contenido.innerHTML = `
<img src="${data.results['0'].picture.large}" width="200px" class="img-fluid rounded-circle">
<br><br>
<b>Name: </b> ${data.results['0'].name.title} ${data.results['0'].name.first} ${data.results['0'].name.last}<br>
<b>Gender: </b> ${data.results['0'].gender}<br>
`
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment