38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
|
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))
|
||
|
})
|