-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.js
More file actions
36 lines (27 loc) · 844 Bytes
/
tutorial.js
File metadata and controls
36 lines (27 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const getTodos = (resourse, callback) => {
const request = new XMLHttpRequest()
request.addEventListener('readystatechange', () => {
if(request.readyState === 4 && request.status === 200){
const data = JSON.parse(request.responseText)
callback(undefined, data )
}else if(request.readyState === 4){
callback('could not fetch data', undefined)
}
})
request.open('GET',resourse)
// https://jsonplaceholder.typicode.com/todos/
request.send()
}
console.log(1);
console.log(2);
getTodos('todos/luigi.json',(err, data) => {
console.log(data );
getTodos('todos/mario.json',(err, data) => {
console.log(data);
getTodos('todos/shaun.json',(err,data) => {
console.log(data);
})
})
})
console.log(3);
console.log(4);