AJAX XMLHttpRequest Object Instance Tutorial
Ajax-More about X-ML HttpRequest objects
In sending data to the server, we have explained three important feature XMLHttpRequest objects.
Ajax onReadyStateChange
After requesting to the server, we need a feature that can receive data that is returned by the server.
onreadystatechange Property stores your functionality and will react to the process from a server.
It is not a method that functions are stored in property that is called automatic running. The following code sets the onReadyStateChange property and an empty function inside the store:
Xmlhttp.onreadystatechange=function ()
{
We are going to write some code here
}
The Ajax ReadyState property's ReadyState property owns the response of the state server.
Each time the readystate changes, the onreadystatechange function will be executed.
The following are the possible values for the ReadyState property:
State Description
0 Request not initialized
1 requirements have been established
2 Request Sent
3 Request one in the process
4 Operation complete
We want to add a declaration if the onReadyStateChange function is tested,
If our reaction is complete (which means we can get our data): Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4)
{
Get the data from the server ' s response
}
}
ResponseText
These data are transmitted back from the server and can be responsetext with the property.
In our code, we will set the value of the "Time" input field equal to ResponseText:
Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4)
{
Document.myform.time.value=xmlhttp.responsetext;
}
}