You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 5-network/01-fetch/article.md
+5-3
Original file line number
Diff line number
Diff line change
@@ -12,11 +12,11 @@ For example, we can use a network request to:
12
12
13
13
...And all of that without reloading the page!
14
14
15
-
There's an umbrella term "AJAX" (abbreviated <b>A</b>synchronous <b>J</b>avaScript <b>A</b>nd <b>X</b>ML) for network requests from JavaScript. We don't have to use XML though: the term comes from old times, that's that word is there. You may have heard that term already.
15
+
There's an umbrella term "AJAX" (abbreviated <b>A</b>synchronous <b>J</b>avaScript <b>A</b>nd <b>X</b>ML) for network requests from JavaScript. We don't have to use XML though: the term comes from old times, that's why that word is there. You may have heard that term already.
16
16
17
17
There are multiple ways to send a network request and get information from the server.
18
18
19
-
The `fetch()` method is modern and versatile, so we'll start with it. It's not supported by old browsers (can be polyfilled), but very well supported among the new ones.
19
+
The `fetch()` method is modern and versatile, so we'll start with it. It's not supported by old browsers (can be polyfilled), but very well supported among the modern ones.
20
20
21
21
The basic syntax is:
22
22
@@ -27,11 +27,13 @@ let promise = fetch(url, [options])
27
27
-**`url`** -- the URL to access.
28
28
-**`options`** -- optional parameters: method, headers etc.
29
29
30
+
Without `options`, that is a simple GET request, downloading the contents of the `url`.
31
+
30
32
The browser starts the request right away and returns a promise that the calling code should use to get the result.
31
33
32
34
Getting a response is usually a two-stage process.
33
35
34
-
**First, the `promise` resolves with an object of the built-in [Response](https://fetch.spec.whatwg.org/#response-class) class as soon as the server responds with headers.**
36
+
**First, the `promise`, returned by `fetch`, resolves with an object of the built-in [Response](https://fetch.spec.whatwg.org/#response-class) class as soon as the server responds with headers.**
35
37
36
38
At this stage we can check HTTP status, to see whether it is successful or not, check headers, but don't have the body yet.
In this example parentheses were used to make a group for repeating`pattern:(...)+`. But there are other uses too, let's see them.
46
+
In this example parentheses were used to make a group for repetitions`pattern:([\w-]+\.)+`. But there are other uses too, let's see them.
47
47
48
48
## Contents of parentheses
49
49
@@ -53,7 +53,7 @@ For instance, we'd like to find HTML tags `pattern:<.*?>`, and process them.
53
53
54
54
Let's wrap the inner content into parentheses, like this: `pattern:<(.*?)>`.
55
55
56
-
We'll get both the tag as a whole and its content as an array:
56
+
Then we'll get both the tag as a whole and its content:
57
57
58
58
```js run
59
59
let str ='<h1>Hello, world!</h1>';
@@ -111,7 +111,7 @@ Then groups, numbered from left to right. Whichever opens first gives the first
111
111
112
112
Then in `result[2]` goes the group from the second opening `pattern:(` till the corresponding `pattern:)` -- tag name, then we don't group spaces, but group attributes for `result[3]`.
113
113
114
-
**If a group is optional and doesn't exist in the match, the corresponding `result`index is present (and equals `undefined`).**
114
+
**Even if a group is optional and doesn't exist in the match, the corresponding `result`array item is present (and equals `undefined`).**
115
115
116
116
For instance, let's consider the regexp `pattern:a(z)?(c)?`. It looks for `"a"` optionally followed by `"z"` optionally followed by `"c"`.
0 commit comments