Skip to content

Commit 181effa

Browse files
Balashov NikitaOlegLustenko
authored andcommitted
classwork-21
1 parent 3f37d23 commit 181effa

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Class work 21</title>
6+
</head>
7+
<body>
8+
<script src="src/main.js"></script>
9+
</body>
10+
</html>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const url = 'https://jsonplaceholder.typicode.com/users/';
2+
3+
const getUser = (userId, callback) => {
4+
const xhr = new XMLHttpRequest();
5+
xhr.onreadystatechange = () => {
6+
if(xhr.readyState === 4) {
7+
const user = JSON.parse(xhr.response);
8+
callback(user);
9+
}
10+
}
11+
xhr.open('GET', `${url}/${userId}`, true);
12+
xhr.send();
13+
}
14+
15+
getUser(1, user1 => {
16+
getUser(2, user2 => {
17+
getUser(3, user3 => {
18+
console.log(user1.id + user2.id + user3.id);
19+
console.log(user1.name + user2.name + user3.name);
20+
})
21+
})
22+
})
23+
24+
25+
// const myPromise = new Promise((resolve, reject) => {
26+
27+
// })
28+
29+
const users = [1, 2, 3];
30+
31+
const usersPromise = users.map(user => {
32+
return fetch(url + user).then(response => response.json());
33+
})
34+
35+
Promise.all(usersPromise)
36+
.then(allUsers => {
37+
console.log(allUsers);
38+
})
39+
40+
const url2 = 'http://easycode-js.herokuapp.com/ollu/users';
41+
42+
fetch(url2)
43+
.then(data => {
44+
return data.json()
45+
})
46+
.then(users => console.log(users));
47+
48+
fetch(url2, {
49+
method: 'POST',
50+
headers: {
51+
'Content-type': 'application/json'
52+
},
53+
body: JSON.stringify({
54+
fullName: 'Leon Kara',
55+
56+
phone: '00000000'
57+
})
58+
})

phone-book/img/avatar.jpg

12.2 KB
Loading

0 commit comments

Comments
 (0)