Skip to content

Commit c822fc7

Browse files
committed
Fetch - Errors "gotcha"
1 parent 43a1e55 commit c822fc7

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

app.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,10 @@
22
// promised based
33
// XHR is not wrong, you can complete all our upcoming examples and projects using XHR. Fetch is just alternative approach that has simpler and cleaner syntax. The end result is the same.Still get dynamically, behind the scenes.
44

5-
const url = "./api/people.json";
6-
7-
/* Returns Promise and the resolve is "response"*/
8-
// const response = fetch(url);
9-
// console.log(response);
10-
11-
// fetch(url)
12-
// .then((response) => {
13-
// // Response Object
14-
// // Useful methods and properties
15-
// // Convert response into JSON data
16-
// // Returns Promise
17-
18-
// console.log(response);
19-
// return response.json();
20-
// })
21-
// .then((data) => console.log(data))
22-
// .catch((error) => console.log(error));
5+
const url = "./api/people.jsons";
236

247
/* Using Implicit Return */
258
fetch(url)
26-
.then((response) => response.json())
9+
.then((response) => console.log(response))
2710
.then((data) => console.log(data))
2811
.catch((error) => console.log(error));

references/fetch.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Fetch built-in
2+
// promised based
3+
// XHR is not wrong, you can complete all our upcoming examples and projects using XHR. Fetch is just alternative approach that has simpler and cleaner syntax. The end result is the same.Still get dynamically, behind the scenes.
4+
5+
const url = "./api/people.json";
6+
7+
/* Returns Promise and the resolve is "response"*/
8+
// const response = fetch(url);
9+
// console.log(response);
10+
11+
// fetch(url)
12+
// .then((response) => {
13+
// // Response Object
14+
// // Useful methods and properties
15+
// // Convert response into JSON data
16+
// // Returns Promise
17+
18+
// console.log(response);
19+
// return response.json();
20+
// })
21+
// .then((data) => console.log(data))
22+
// .catch((error) => console.log(error));
23+
24+
/* Using Implicit Return */
25+
fetch(url)
26+
.then((response) => response.json())
27+
.then((data) => console.log(data))
28+
.catch((error) => console.log(error));

0 commit comments

Comments
 (0)