Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Nossos voluntários ainda não traduziram este artigo para o Português (do Brasil) . Junte-se a nós e ajude a fazer o trabalho!

An EventHandler that is called whenever the readyState attribute changes. The callback is called from the user interface thread. The XMLHttpRequest.onreadystatechange property contains the event handler to be called when the readystatechange event is fired, that is every time the readyState property of the XMLHttpRequest changes. The callback is called from the user interface thread.

Warning: This should not be used with synchronous requests and must not be used from native code.

The readystatechange event will not be fired when an XMLHttpRequest request is canceled with the abort() method.

Syntax

XMLHttpRequest.onreadystatechange = callback;

Values

  • callback is the function to be executed when the readyState changes.

Example

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();

Specifications

Specification Status Comment
XMLHttpRequest Living Standard WHATWG living standard

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1 1.0 (1.7 or earlier) 7[1] (Yes) 1.2
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 1.0 (Yes) ? ? ?

[1] Internet Explorer version 5 and 6 supported ajax calls using ActiveXObject().

Etiquetas do documento e colaboradores

 Última atualização por: sean-roberts,