--- title: XMLHttpRequest.onreadystatechange slug: Web/API/XMLHttpRequest/onreadystatechange translation_of: Web/API/XMLHttpRequest/onreadystatechange ---
UN EventHandler che è invocato ogni volta che l'attributo readyState cambia. la callback è invocata dal thread dell'interfaccia utente.
La proprietà XMLHttpRequest.onreadystatechange contiene l'event handler che deve essere invocato quando l'evento {{event("readystatechange")}} si verifica, ovvero ogni volta in cui la proprietà {{domxref("XMLHttpRequest.readyState", "readyState")}} del {{domxref("XMLHttpRequest")}} viene modificata.
Warning: This should not be used with synchronous requests and must not be used from native code. .
L'evento readystatechange non si verificherà se una richiesta XMLHttpRequest viene cancellata utilizzando il metodo abort().
UPDATE: it's firing in the latest version of browsers (Firefox 51.0.1, Opera 43.0.2442.991, Safari 10.0.3 (12602.4.8), Chrome 54.0.2840.71, Edge, IE11). Example here - just reaload page few times.
XMLHttpRequest.onreadystatechange = callback;
callback è la funzione che viene eseguita quando readyState cambia.var xhr = new XMLHttpRequest(),
method = "GET",
url = "https://developer.mozilla.org/";
xhr.open(method, url, true);
xhr.onreadystatechange = function () {
if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
console.log(xhr.responseText);
}
};
xhr.send();
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('XMLHttpRequest', '#handler-xhr-onreadystatechange')}} | {{Spec2('XMLHttpRequest')}} | WHATWG living standard |
{{CompatibilityTable}}
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | {{CompatChrome(1)}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop(1.0)}} | {{CompatIe(7)}}[1] | {{CompatVersionUnknown}} | {{CompatSafari(1.2)}} |
| Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | {{CompatUnknown}} | 1.0 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
[1] Internet Explorer version 5 and 6 supported ajax calls using ActiveXObject().