const criaNovaLinha = (nome, email) => { const linhaNovoCliente = document.createElement('tr'); const conteudo = `
${nome} | ${email} |
linhaNovoCliente.innerHTML = conteudo
return linhaNovoCliente;
}
const tabela = document.querySelector('[data-tabela]')
const listaClientes = () => { const promise = new Promise((resolve, reject) => { const http = new XMLHttpRequest() http.open('GET', 'http://localhost:3000/profile'); http.onload = () => { if (http.status >= 400) { reject(JSON.parse(http.response)) } else { resolve(JSON.parse(http.response)) } } http.send()
})
return promise
}
listaClientes() .then((data) => { data.forEach(elemento => { tabela.appendChild(criaNovaLinha(elemento.nome, elemento.email)) }) })