This commit is contained in:
szabomarton 2024-11-18 13:41:34 +01:00
parent 6146ada108
commit 4d0bd470bb
3 changed files with 92 additions and 0 deletions

34
20241118_JS/feladat1.html Normal file
View File

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
<select name="selection" id="selection">
<option value="1">
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
</select>
</form>
<button id="button">Lekér</button>
<div id="eredmeny"></div>
<script src="feladat1.js" defer></script>
</body>
</html>

57
20241118_JS/feladat1.js Normal file
View File

@ -0,0 +1,57 @@
const url = "http://127.0.0.1/PHP_digivagyok/20241118_JS/munkasok.json";
document.getElementById("button").addEventListener("click", function(){
let value = document.getElementById("selection").value;
console.log(value);
main(value);
});
/*
async function main(munkasNumber) {
let xhttp = new XMLHttpRequest();
xhttp.open("GET", url, true);
xhttp.onreadystatechange = async function(){
if (xhttp.readyState === 4){
if (xhttp.status === 200){
let sol = await JSON.parse(xhttp.responseText);
console.log(sol);
createDomElement(sol[munkasNumber - 1]);
} else if(xhttp.status === 404){
console.log("Az erőforrás nem található - 404 hibakód");
} else{
console.error(`Hiba történt, státuszkód: ${xhttp.status}`);
}
}
}
xhttp.send();
}
*/
async function main(munkasNumber) {
try{
let response = await fetch(url);
if (!response.ok){
throw new Error(`Hiba történt: ${response.status}`);
}
let adatok = await response.json();
createDomElement(adatok[munkasNumber - 1]);
} catch (error) {
console.error(`Hiba ${error}`);
}
}
function createDomElement(element) {
let line = document.createElement("div");
line.innerHTML = `Név: ${element.nev}, Beosztás: ${element.beosztas}, Kor: ${element.kor}, Fizetés:${element.fizetes}Ft`;
document.getElementById("eredmeny").appendChild(line);
}

View File

@ -0,0 +1 @@
[{"nev":"Jani","beosztas":"sofőr","kor":45,"fizetes":300000},{"nev":"Pali","beosztas":"naplopó","kor":37,"fizetes":250000},{"nev":"Laci","beosztas":"vezető","kor":46,"fizetes":380000},{"nev":"Zsolt","beosztas":"főnök","kor":25,"fizetes":3000000},{"nev":"Tihamér","beosztas":"sofőr","kor":30,"fizetes":300000}]