added Kutya

This commit is contained in:
Digi
2024-12-14 14:50:02 +01:00
parent c913243b67
commit 51551b918c
26 changed files with 16425 additions and 0 deletions

55
ajax_fetch.js Normal file
View File

@@ -0,0 +1,55 @@
const url = "https://jsonplaceholder.typicode.com/posts";
async function fetchAPI() {
try{
let result = await fetch(url,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(
{
name: "Szabó Márton",
email: "@mail"
}
)
}
);
let data = await result.json();
console.log(data);
} catch (error){
console.error(error);
} finally {
console.log("All done.")
}
}
async function ajax() {
let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = async function(){
if (xhr.readyState === 4){
if (xhr.status === 200){
console.log("asd");
let sol = await JSON.parse(xhr.responseText);
//let sol = await JSON.parse(JSON.stringify(xhttp.responseText));
sol.forEach(element => {
if (element.id > 0 && element.id < 4){
console.log(element);
}
});
} else if(xhr.status == 400){
console.error("Az erőforrás nem található");
} else {
console.error(`Hiba kód: ${xhr.status}`);
}
}
}
xhr.send();
}
//fetchAPI();
ajax();