Skip to content

Translate "AJAX and APIs" into Russian #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions content/docs/faq-ajax.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
id: faq-ajax
title: AJAX and APIs
title: Запрос к серверу, AJAX и APIs
permalink: docs/faq-ajax.html
layout: docs
category: FAQ
---

### How can I make an AJAX call? {#how-can-i-make-an-ajax-call}
### Как выполнить AJAX запрос к серверу? {#how-can-i-make-an-ajax-call}

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).
Используйте любую AJAX библиотеку, например [Axios](https://github.com/axios/axios) или [jQuery AJAX](https://api.jquery.com/jQuery.ajax/). А еще присмотритесь к встроенному в браузер методу [window.fetch](https://learn.javascript.ru/fetch).

### Where in the component lifecycle should I make an AJAX call? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call}
### Где в жизненном цикле компонента я могу сделать AJAX запрос? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call}

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.
В методе [`componentDidMount`](/docs/react-component.html#mounting). Сделайте AJAX запрос и используйте `setState` для обновления компонента когда данные будут получены.

### Example: Using AJAX results to set local state {#example-using-ajax-results-to-set-local-state}
### Пример: Результат AJAX запроса и установка внутреннего состояния {#example-using-ajax-results-to-set-local-state}

The component below demonstrates how to make an AJAX call in `componentDidMount` to populate local component state.
Компонент ниже демонстрирует как сделать AJAX запрос в `componentDidMount` для дальнейшего обновления внутреннего состояния.

The example API returns a JSON object like this:
Допустим, наш API возвращает следующий JSON-объект:

```
{
Expand Down Expand Up @@ -50,9 +50,8 @@ class MyComponent extends React.Component {
items: result.items
});
},
// Note: it's important to handle errors here
// instead of a catch() block so that we don't swallow
// exceptions from actual bugs in components.
// Примечание: важно обрабатывать ошибки именно здесь, а не в блоке catch(),
// чтобы не проглотить исключения из-за настоящих багов в компонентах.
(error) => {
this.setState({
isLoaded: true,
Expand All @@ -65,9 +64,9 @@ class MyComponent extends React.Component {
render() {
const { error, isLoaded, items } = this.state;
if (error) {
return <div>Error: {error.message}</div>;
return <div>Ошибка: {error.message}</div>;
} else if (!isLoaded) {
return <div>Loading...</div>;
return <div>Загрузка...</div>;
} else {
return (
<ul>
Expand Down
2 changes: 1 addition & 1 deletion content/docs/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
- title: FAQ
items:
- id: faq-ajax
title: AJAX and APIs
title: Запрос к серверу, AJAX и APIs
- id: faq-build
title: Babel, JSX, and Build Steps
- id: faq-functions
Expand Down