Kingston_Pendrive/Suli/13.b/Frontend/Javascript/2024. 11. 18/public/js/scriptFetch.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-11-19 18:04:02 +00:00
const lekerdezes = document.getElementById("lekerdezes")
const bekuldes = document.getElementById("bekuldes")
lekerdezes.addEventListener("click", () => {
fetch("http://localhost:3000/json/munkavallalok.json")
.then(result => result.json())
.then(munkavallalok => {
const munkavallalo = munkavallalok[document.querySelector("select").selectedIndex]
const eredmenyDiv = document.querySelector("div")
eredmenyDiv.innerHTML = `
Név: ${munkavallalo["nev"]},
Beosztás: ${munkavallalo["beosztas"]},
Kor: ${munkavallalo["kor"]},
Fizetés: ${munkavallalo["fizetes"]}
`
})
})
bekuldes.addEventListener("click", () => {
const munkavallalo = document.querySelector("textarea").value.split("\n")
fetch("/feltoltes", {
method: "POST",
headers: {
"Content-type": "application/json"
},
body: JSON.stringify({
nev: munkavallalo[0],
beosztas: munkavallalo[1],
kor: munkavallalo[2],
fizetes: munkavallalo[3]
})
})
.then(response => response.json())
.then(data => console.log(data))
})