The Wayback Machine - https://web.archive.org/web/20150909220943/https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/onreadystatechange

onreadystatechange

by 3 contributors:

This article is in need of a technical review.

Summary

The onreadystatechange event is triggered every time the readyState attribute of the XMLHttpRequest changes. The callback is called from the user interface thread.

Syntax

XMLHttpRequest.onreadystatechange = callback;

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

Example

var xmlhttp = new XMLHttpRequest() , method = 'GET' , url = 'https://developer.mozilla.org/';
xmlhttp.open( method , url , true );
xmlhttp.onreadystatechange = function () {
    if ( 4 != xmlhttp.readyState ) {
        return;
    }
    if ( 200 != xmlhttp.status ) {
        return;
    }
    console.log( xmlhttp.responseText );
};
xmlhttp.send();

Document Tags and Contributors

Tags: 
Contributors to this page: imme_emosol, JiangSheng, mlcheng
Last updated by: imme_emosol,