added things
This commit is contained in:
parent
0ca86bd7c1
commit
d4bdf90b83
10
24_11_18/asd.php
Normal file
10
24_11_18/asd.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
|
||||
echo '{
|
||||
"data": "value"
|
||||
}';
|
||||
}
|
||||
|
||||
|
||||
?>
|
45
24_11_18/feladat2.html
Normal file
45
24_11_18/feladat2.html
Normal file
|
@ -0,0 +1,45 @@
|
|||
<!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>
|
||||
<form>
|
||||
Név:
|
||||
<input type="text" id="nev"> <br>
|
||||
Beosztás:
|
||||
<input type="text" id="beosztas"> <br>
|
||||
Kor:
|
||||
<input type="number" id="kor" min="1" > <br>
|
||||
Fizetés:
|
||||
<input type="number" id="fizetes">
|
||||
</form>
|
||||
<button id="hozzaAdGomb">Elem hozzáadása</button>
|
||||
<div id="eredmeny"></div>
|
||||
<script src="feladat2.js" defer></script>
|
||||
</body>
|
||||
</html>
|
77
24_11_18/feladat2.js
Normal file
77
24_11_18/feladat2.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
const url = "http://127.0.0.1/Digivagyok/munkasok.json";
|
||||
|
||||
document.getElementById("button").addEventListener("click", function(){
|
||||
let value = document.getElementById("selection").value;
|
||||
console.log(value);
|
||||
main(value);
|
||||
});
|
||||
|
||||
document.getElementById("hozzaAdGomb").addEventListener("click", function(){
|
||||
let nev = document.getElementById("nev").value;
|
||||
let beosztas = document.getElementById("beosztas").value;
|
||||
let kor = document.getElementById("kor").value;
|
||||
let fizetes = document.getElementById("fizetes").value;
|
||||
|
||||
let munkas = {
|
||||
nev: nev,
|
||||
beosztas: beosztas,
|
||||
kor: kor,
|
||||
fizetes: fizetes
|
||||
}
|
||||
|
||||
adatfeltoltes(munkas);
|
||||
|
||||
});
|
||||
|
||||
async function adatfeltoltes(munkas) {
|
||||
let xhttp = new XMLHttpRequest();
|
||||
xhttp.open("POST", "asd.php", true);
|
||||
xhttp.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
|
||||
xhttp.onreadystatechange = async function(){
|
||||
if (xhttp.readyState === 4){
|
||||
if (xhttp.status === 201){
|
||||
let sol = await JSON.parse(xhttp.responseText);
|
||||
|
||||
console.log("A munkás sikeresen hozzá lett adva a munkásokhoz.");
|
||||
console.log(sol);
|
||||
} else if (xhttp.status === 200){
|
||||
let sol = await JSON.parse(xhttp.responseText);
|
||||
|
||||
console.log("A munkás sikeresen hozzá lett adva a munkásokhoz.");
|
||||
console.log(sol);
|
||||
} 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("format=json");
|
||||
|
||||
xhttp.send(JSON.stringify(munkas));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user