54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
const lekerdezes = document.getElementById("lekerdezes")
|
|
const bekuldes = document.getElementById("bekuldes")
|
|
|
|
lekerdezes.addEventListener("click", () => {
|
|
let xhttp = new XMLHttpRequest()
|
|
xhttp.open("GET", "../json/munkavallalok.json", true)
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
if (xhttp.readyState === 4) {
|
|
if (xhttp.status === 200) {
|
|
const munkavallalok = JSON.parse(xhttp.responseText)
|
|
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"]}
|
|
`
|
|
} else if (xhttp.status === 404) {
|
|
console.log("Erőforrás nem található - 404-es hibakód")
|
|
} else {
|
|
console.log(`Hiba történt, státuszkód: ${xhttp.status}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
xhttp.send()
|
|
})
|
|
|
|
bekuldes.addEventListener("click", () => {
|
|
let xhttp = new XMLHttpRequest()
|
|
xhttp.open("POST", "/feltoltes", true)
|
|
xhttp.setRequestHeader('Content-type', 'application/json; charset=UTF-8')
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
if (xhttp.readyState === 4) {
|
|
if (xhttp.status === 201) {
|
|
console.log(JSON.parse(xhttp.responseText));
|
|
}
|
|
}
|
|
}
|
|
|
|
const munkavallalo = document.querySelector("textarea").value.split("\n")
|
|
const munkavallaloJSON = JSON.stringify({
|
|
nev: munkavallalo[0],
|
|
beosztas: munkavallalo[1],
|
|
kor: munkavallalo[2],
|
|
fizetes: munkavallalo[3]
|
|
})
|
|
|
|
xhttp.send(munkavallaloJSON)
|
|
}) |