Un EventHandler
qui réagit aux changements de readyState
. Le callback est appelé dans le contexte du thread de rendu. La propriété XMLHttpRequest.onreadystatechange
contient le gestionnaire d'évènement appelé lorsque l'évènement readystatechange
est déclenché, soit chaque fois que la propriété readyState
de XMLHttpRequest
est modifiée.
Attention: Ne doit pas être utilisé avec des requêtes synchrone ni avec du code natif.
Syntaxe
XMLHttpRequest.onreadystatechange = callback;
Valeurs
callback
est la fonction exécutée lorsquereadyState
change.
Exemple
var xhr = new XMLHttpRequest(),
method = "GET",
url = "https://developer.mozilla.org/";
xhr.open(method, url, true);
xhr.onreadystatechange = function () {
if(xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
}
};
xhr.send();
Spécifications
Specification | Status | Comment |
---|---|---|
XMLHttpRequest | Standard évolutif | WHATWG living standard |
Compatibilité des fureteurs
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.