-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
91 lines (76 loc) · 3.09 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
title: XMLHttpRequest.readyState
slug: Web/API/XMLHttpRequest/readyState
---
{{APIRef('XMLHttpRequest')}}
La propriété XMLHttpRequest.readyState renvoie l'état dans lequel se trouve un client XMLHttpRequest.Un client XHR existe dans l'un des états suivants :
<table class="standard-table">
<tbody>
<tr>
<td class="header">Value</td>
<td class="header">State</td>
<td class="header">Description</td>
</tr>
<tr>
<td><code>0</code></td>
<td><code>UNSENT</code></td>
<td>Le client a été créé. open() n'a pas encore été appelé.</td>
</tr>
<tr>
<td><code>1</code></td>
<td><code>OPENED</code></td>
<td><code>open()</code>a été appelé.</td>
</tr>
<tr>
<td><code>2</code></td>
<td><code>HEADERS_RECEIVED</code></td>
<td>
<code>send()</code> a été appelé, et les en-têtes et le statut sont
disponibles.
</td>
</tr>
<tr>
<td><code>3</code></td>
<td><code>LOADING</code></td>
<td>
Téléchargement; <code>responseText</code> contient des données
partielles.
</td>
</tr>
<tr>
<td><code>4</code></td>
<td><code>DONE</code></td>
<td>L'opération est terminée.</td>
</tr>
</tbody>
</table>
- UNSENT
- : Le client XMLHttpRequest a été créé, mais la méthode open() n'a pas encore été appelée.
- OPENED
- : La méthode open() a été invoquée. Pendant cet état, les en-têtes de requête peuvent être définis à l'aide de la méthode [setRequestHeader()](/fr/docs/Web/API/XMLHttpRequest/setRequestHeader) et la méthode [send()](/fr/docs/Web/API/XMLHttpRequest/send) peut être appelée, ce qui lancera la récupération.
- HEADERS_RECEIVED
- : send() a été appelé et les en-têtes de réponse ont été reçus
- LOADING
- : Le corps de la réponse est en cours de réception. Si [`responseType`](/fr/docs/Web/API/XMLHttpRequest/responseType) is "text" ou une chaîne vide, [`responseText`](/fr/docs/Web/API/XMLHttpRequest/responseText) aura la réponse textuelle partielle au fur et à mesure de son chargement.
- DONE
- : L'opération de récupération est terminée. Cela peut signifier que le transfert de données a été effectué avec succès ou a échoué.
> [!NOTE]
> Les noms des états sont différents dans les versions d'Internet Explorer antérieures à 11. Au lieu de `UNSENT`, `OPENED`, `HEADERS_RECEIVED`, `LOADING` et `DONE`, les noms `READYSTATE_UNINITIALIZED` (0), `READYSTATE_LOADING` (1), `READYSTATE_LOADED` (2), `READYSTATE_INTERACTIVE` (3) et `READYSTATE_COMPLETE` (4) sont utilisés.
## Exemple
```js
var xhr = new XMLHttpRequest();
console.log("UNSENT", xhr.readyState); // readyState will be 0
xhr.open("GET", "/api", true);
console.log("OPENED", xhr.readyState); // readyState will be 1
xhr.onprogress = function () {
console.log("LOADING", xhr.readyState); // readyState will be 3
};
xhr.onload = function () {
console.log("DONE", xhr.readyState); // readyState will be 4
};
xhr.send(null);
```
## Spécifications
{{Specifications}}
## Compatibilité des navigateurs
{{Compat}}