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.
The readystatechange
event will not be fired when an XMLHttpRequest
request is canceled with the abort() method.
SyntaxEdit
XMLHttpRequest.onreadystatechange = callback;
Values
callback
is the function to be executed when thereadyState
changes.
ExampleEdit
var xmlhttp = new XMLHttpRequest(),
method = "GET",
url = "https://developer.mozilla.org/";
xmlhttp.open(method, url, true);
xmlhttp.onreadystatechange = function () {
if(xmlhttp.readyState === XMLHttpRequest.DONE && xmlhttp.status === 200) console.log(xmlhttp.responseText);
};
xmlhttp.send();
SpecificationsEdit
Specification | Status | Comment |
---|---|---|
XMLHttpRequest | Living Standard | WHATWG living standard |
Browser compatibilityEdit
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1 | 1.0 (1.7 or earlier) | 7[1] | (Yes) | 1.2 |
[1] Internet Explorer version 5 and 6 supported ajax calls using ActiveXObject()
.
Document Tags and Contributors
Tags:
Contributors to this page:
K._,
jsx,
maybe,
andela-abankole,
teoli,
imme_emosol,
JiangSheng,
mlcheng
Last updated by:
K._,