|
1 | 1 | ---
|
2 | 2 | id: faq-ajax
|
3 |
| -title: AJAX and APIs |
| 3 | +title: AJAX و APIs |
4 | 4 | permalink: docs/faq-ajax.html
|
5 | 5 | layout: docs
|
6 | 6 | category: FAQ
|
7 | 7 | ---
|
| 8 | + |
| 9 | +### كيف يمكنني إجراء استدعاء في AJAX؟ {#how-can-i-make-an-ajax-call} |
8 | 10 |
|
9 |
| -### How can I make an AJAX call? {#how-can-i-make-an-ajax-call} |
| 11 | +بإمكانك استخدام أي مكتبة AJAX تريدها مع React. من المكتبات الشائعة هنالك [Axios](https://github.com/axios/axios), [jQuery AJAX](https://api.jquery.com/jQuery.ajax/), والمكتبة المُضمَّنة مع المتصفح والتي تُدعى [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). |
10 | 12 |
|
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). |
| 13 | +### في أي تابع من توابع دورة الحياة يجب عليّ إجراء استدعاء AJAX؟ {#where-in-the-component-lifecycle-should-i-make-an-ajax-call} |
12 | 14 |
|
13 |
| -### Where in the component lifecycle should I make an AJAX call? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call} |
| 15 | +يجب عليك الحصول على البيانات عن طريق استدعاء AJAX في تابع دور الحياة [`componentDidMount`](/docs/react-component.html#mounting). وهذا لكي تستطيع استخدام التابع `setState` لتحديث مكوّنك عند استقبال البيانات. |
14 | 16 |
|
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. |
| 17 | +### مثال: استخدام نتائج AJAX لتعيين الحالة المحلية {#example-using-ajax-results-to-set-local-state} |
16 | 18 |
|
17 |
| -### Example: Using AJAX results to set local state {#example-using-ajax-results-to-set-local-state} |
| 19 | +يُوضّح المكوّن التالي كيفيّة إجراء استدعاء AJAX ضمن التابع `componentDidMount` لتعيين الحالة المحليّة للمكوّن. |
18 | 20 |
|
19 |
| -The component below demonstrates how to make an AJAX call in `componentDidMount` to populate local component state. |
20 |
| - |
21 |
| -The example API returns a JSON object like this: |
| 21 | +تُعيد واجهة برمجة التطبيق في هذا المثال كائن JSON مشابه لما يلي: |
22 | 22 |
|
23 | 23 | ```
|
24 | 24 | {
|
@@ -50,9 +50,9 @@ 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 | + // ملاحظة: من الهام التعامل مع الأخطاء هنا |
| 54 | + // catch() بدلًا من من استخدام الكتلة |
| 55 | + // لكي لا نقبل الاستثناءات من أخطاء فعليّة في المكوّنات |
56 | 56 | (error) => {
|
57 | 57 | this.setState({
|
58 | 58 | isLoaded: true,
|
|
0 commit comments