-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
37 lines (30 loc) · 946 Bytes
/
main.js
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
function fazGet(url) {
let request = new XMLHttpRequest();
request.open('GET', url, false);
request.send();
return request.responseText;
}
function criaLinha(usuario) {
console.log(usuario)
document.createElement('tr'); //cria linha
td = document.createElement('td'); //cria coluna
tdNome = document.createElement('td');
tdId.innerHTML = usuario.id; //add filho
tdNome.innerHTML = usuario.name;
linha.appendChild(tdId);
linha.appendChild(tdNome);
return linha;
}
function main() {
let data = fazGet('http://127.0.0.1:5000/get/usuarios');
let usuarios = JSON.parse(data);
let tabela = document.getElementById('tabela')
usuarios.forEach(element => {
let linha = criaLinha(element); //pega linha que foi criada e add na tabela
tabela.appendChild(linha);
})
// Para cada usuario
// criar uma linha
// adicionar na tabela
}
main();