Rest API teszt
This commit is contained in:
1 parent
f2c32b0c9b
commit
b4e90847af
3 files changed
+52
No files matched your search
@@ -0,0 +1,25 @@
|
||||
|
||||
// fetch('https://jsonplaceholder.typicode.com/posts')
|
||||
// .then(res=>res.json())
|
||||
// .then(adatok=>console.log(adatok))
|
||||
// .catch(err=>console.log(err))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async function letolt() {
|
||||
try {
|
||||
let keres=await fetch('https://jsonplaceholder.typicode.com/posts/1');
|
||||
let valasz=await keres.json();
|
||||
|
||||
console.log(valasz);
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
letolt();
|
||||
|
||||
console.log("Valami");
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Posts</title>
|
||||
<script defer src="posts.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,15 @@
|
||||
let keres=new XMLHttpRequest();
|
||||
let valasz="";
|
||||
|
||||
keres.open('GET','https://jsonplaceholder.typicode.com/posts',true);
|
||||
|
||||
keres.onload=function(){
|
||||
valasz=JSON.parse(this.response);
|
||||
console.log(valasz);
|
||||
}
|
||||
|
||||
keres.send();
|
||||
|
||||
console.log("Válasz:"+valasz);
|
||||
|
||||
|
||||
Reference in new issue
Block a user