AJAX properties
onreadystatechange property
The onreadystatechange property is used to receive information returned by the web server. This property stores the function that will process the response from the web server.
Example:
<script type="text/javascript">
ajaxObject = XMLHttpRequest();
ajaxObject.onreadystatechange = function(){
//code for the function that will
//process the response from the web server
}
</script>
readyState property
The readyState property is used to store the status of the web server's response. When the readyState property changes, the function created by onreadystatechange executes.
Possible values for the readyState property and what they mean:
| Value | Meaning |
|---|---|
| 0 | Request has not been initialized |
| 1 | Request is set up |
| 2 | Request is sent |
| 3 | Request is in process |
| 4 | Request is complete |
Example:
<script type="text/javascript">
ajaxObject = XMLHttpRequest();
ajaxObject.onreadystatechange = function(){
//if request is complete (4)
if(ajaxRequest.readyState == 4){
// get data from
//web server's response
}
}
</script>
responseText property
The responseText property is used to store the actual information received by the web server.
Example:
<script type="text/javascript">
ajaxObject = XMLHttpRequest();
ajaxObject.onreadystatechange = function(){
//if request is complete (4)
if(ajaxRequest.readyState == 4){
// get data from
//web server's response
document.form1.text.value = ajaxRequest.responseText;
}
}
</script>
In the above example, a textbox named 'text' in a form named 'form1' is updated with the value from the responseText property.




