-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercicio-checkout-api-listar-meios-pagamento.html
46 lines (41 loc) · 1.55 KB
/
exercicio-checkout-api-listar-meios-pagamento.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<body>
<form onsubmit="listarMeiosPagamentos(event)">
<br>
<button type="button" onclick="listarMeiosPagamentos(event)">Listar meios pagamento</button>
<br>
<div id="listapagamentos"></div>
</form>
<script>
async function listarMeiosPagamentos(event) {
event.preventDefault();
fetch("http://localhost:9099/exercicio-onboarding-guilherme-fernandes/api/v1/meios-pagamento/listar", { method: 'GET' })
.then((response) => {
return response.json();
})
.then((jsonBody) => {
console.log(jsonBody);
const listaMeiosPagamento = document.getElementById('listapagamentos');
const tempOptions = document.createDocumentFragment();
const table = document.createElement('table');
jsonBody.forEach( option => {
const td = document.createElement('td');
const img = document.createElement('img');
img.src = option.thumbnail;
const name = document.createElement('span');
const br = document.createElement('br');
name.textContent = option.name;
td.appendChild(img);
td.appendChild(name);
const tr = document.createElement('tr');
tr.appendChild(td);
table.appendChild(br);
table.appendChild(tr);
});
listaMeiosPagamento.appendChild(table);
})
.catch((error) => {
console.error('There was an error!', error);
});
}
</script>
</body>