Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.

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.

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

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 === 4 && xhr.status === 200) {
    console.log(xhr.responseText);
  }
};
xhr.send();

Specifications

Specification Status Comment
XMLHttpRequest Living Standard WHATWG living standard

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support112171 Yes1.2
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support118 Yes4 Yes ? Yes

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

Schlagwörter des Dokuments und Mitwirkende

Zuletzt aktualisiert von: SteveVS,