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: content/docs/faq-ajax.md
+12-13Lines changed: 12 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
2
id: faq-ajax
3
-
title: AJAX and APIs
3
+
title: AJAX и обращение к API
4
4
permalink: docs/faq-ajax.html
5
5
layout: docs
6
6
category: FAQ
7
7
---
8
8
9
-
### How can I make an AJAX call? {#how-can-i-make-an-ajax-call}
9
+
### Как выполнить AJAX-запрос к серверу? {#how-can-i-make-an-ajax-call}
10
10
11
-
You can use any AJAX library you like with React. Some popular ones are[Axios](https://github.com/axios/axios), [jQuery AJAX](https://api.jquery.com/jQuery.ajax/), and the browser built-in [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
11
+
Вы можете использовать встроенный в браузер метод [window.fetch](https://learn.javascript.ru/fetch) или любую AJAX-библиотеку, например[Axios](https://github.com/axios/axios) или [jQuery AJAX](https://api.jquery.com/jQuery.ajax/).
12
12
13
-
### Where in the component lifecycle should I make an AJAX call? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call}
13
+
### Где в жизненном цикле компонента лучше делать запрос? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call}
14
14
15
-
You should populate data with AJAX calls in the [`componentDidMount`](/docs/react-component.html#mounting) lifecycle method. This is so you can use `setState` to update your component when the data is retrieved.
15
+
Вы можете сделать AJAX-запрос в [`componentDidMount`](/docs/react-component.html#mounting). Когда вы получите данные, вызовите `setState`, чтобы передать их компоненту.
16
16
17
-
### Example: Using AJAX results to set local state {#example-using-ajax-results-to-set-local-state}
17
+
### Пример: Устанавливаем состояние из AJAX-запроса {#example-using-ajax-results-to-set-local-state}
18
18
19
-
The component below demonstrates how to make an AJAX call in `componentDidMount`to populate local component state.
19
+
Компонент ниже показывает, как в `componentDidMount`задать внутреннее состояние из результата AJAX-запроса.
20
20
21
-
The example API returns a JSON object like this:
21
+
Допустим, наш API возвращает следующий JSON-объект:
22
22
23
23
```
24
24
{
@@ -50,9 +50,8 @@ class MyComponent extends React.Component {
50
50
items:result.items
51
51
});
52
52
},
53
-
// Note: it's important to handle errors here
54
-
// instead of a catch() block so that we don't swallow
55
-
// exceptions from actual bugs in components.
53
+
// Примечание: важно обрабатывать ошибки именно здесь, а не в блоке catch(),
54
+
// чтобы не перехватывать исключения из ошибок в самих компонентах.
56
55
(error) => {
57
56
this.setState({
58
57
isLoaded:true,
@@ -65,9 +64,9 @@ class MyComponent extends React.Component {
0 commit comments