--- title: XMLHttpRequest.onreadystatechange slug: Web/API/XMLHttpRequest/onreadystatechange translation_of: Web/API/XMLHttpRequest/onreadystatechange --- <div>{{APIRef}}</div> <p>Un <a href="/en-US/docs/Web/API/EventHandler" title="A possible way to get notified of Events of a particular type (such as click) for a given object is to specify an event handler using:"><code>EventHandler</code></a> qui réagit aux changements de <code>readyState</code>. Le callback est appelé dans le contexte du thread de rendu. La propriété <strong><code>XMLHttpRequest.onreadystatechange</code></strong> contient le gestionnaire d'évènement appelé lorsque l'évènement {{event("readystatechange")}} est déclenché, soit chaque fois que la propriété {{domxref("XMLHttpRequest.readyState", "readyState")}} de {{domxref("XMLHttpRequest")}} est modifiée.</p> <div class="warning"> <p><strong>Attention:</strong> Ne doit pas être utilisé avec des requêtes synchrone ni avec du code natif.</p> </div> <h2 id="Syntax" name="Syntax">Syntaxe</h2> <pre class="syntaxbox"><em>XMLHttpRequest</em>.onreadystatechange = <em>callback</em>;</pre> <h3 id="Valeurs">Valeurs</h3> <ul> <li><code><em>callback</em></code> est la fonction exécutée lorsque <code>readyState</code> change.</li> </ul> <h2 id="Example" name="Example">Exemple</h2> <pre class="brush: js">var xhr = new XMLHttpRequest(), method = "GET", url = "https://developer.mozilla.org/"; xhr.open(<em>method</em>, <em>url</em>, true); xhr.onreadystatechange = function () { if(xhr.readyState === 4 && xhr.status === 200) { console.log(xhr.responseText); } }; xhr.send();</pre> <h2 id="Spécifications">Spécifications</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> <tr> <td>{{SpecName('XMLHttpRequest', '#handler-xhr-onreadystatechange')}}</td> <td>{{Spec2('XMLHttpRequest')}}</td> <td>WHATWG living standard</td> </tr> </tbody> </table> <h2 id="Compatibilité_des_fureteurs">Compatibilité des fureteurs</h2> <p>{{Compat("api.XMLHttpRequest.onreadystatechange")}}</p>