Código uso de librería AJAX
Pregunta
Sebastián Lastre@sebastianlastre
/* aquí código librería AJAX */
const showMarvel = async () => {
const hash = ''
const apikey = ''
const url = `https://gateway.marvel.com:443/v1/public/characters?ts=1&apikey=${apikey}&hash=${hash}&limit=20&nameStartsWith=iron%20man`
const r = {method: 'GET', url: url}
const response = await ajax(r)
switch (response.status) {
case 200:
console.log(JSON.parse(response.responseText))
draw(JSON.parse(response.responseText).data.results)
break
case 400:
setText('Error de cliente ' + response.status)
break
default:
setText('Error descocido ' + response.status)
}
}
const draw = data => {
const fragment = document.createDocumentFragment()
data.forEach(comic => {
const container = document.createElement('div')
const title = document.createElement('h2')
const image = document.createElement('img')
title.textContent = comic.name
image.src = `${comic.thumbnail.path}/portrait_incredible.${comic.thumbnail.extension}`
container.appendChild(title)
container.appendChild(title)
fragment.appendChild(container)
})
myContent.appendChild(fragment)
}
btn.addEventListener('click', e => {showMarvel()})