-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.json
More file actions
52 lines (49 loc) · 1.83 KB
/
db.json
File metadata and controls
52 lines (49 loc) · 1.83 KB
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
47
48
49
50
51
52
let butPost = document.querySelector('#butTienda').addEventListener("click", post);
let getPost = document.getElementById('getTienda').addEventListener("click", getItems());
let deletePost = document.querySelector("#deleteItem").addEventListener("click", deleteItem);
async function post() {
let div = document.querySelector(".seGuardo");
div.innerHTML = "Guardando...*";
let url = `https://web-unicen.herokuapp.com/api/groups/ejemplos/nombres`;
let title = {
"thing": {
//"userId": 1,
"nombre": "Riquelme",
//"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
}
};
try {
let r = await fetch(url, {
'method': "POST",
'headers': {
'Content-Type': 'aplication-json'
},
'body': JSON.stringify(title),
});
let json = r.json();
console.log(json);
console.log(title);
div.innerHTML = "se guardo :)";
} catch {
console.log(e);
for (index in e) {
console.log(index + ' (' + (typeof e[index]) + '): ' + e[index]);
}
}
}
async function getItems() {
let div = document.getElementsByClassName("Items");
let url = `https://web-unicen.herokuapp.com/api/groups/ejemplos/nombres`;
let r = await fetch(url);
let json = r.json();
try {
for (const elem of json.nombres) {
// html += "<p>" + elem.thing.title + "</p>"; mala practica
let p = document.createElement("p"); //{
p.innerHTML = elem.thing.nombre; // BUENA PRACTICA
div.appendChild(p); //}
}
} catch (e) {
console.log(e);
}
}