Ready-State-Values
Initially copy the XMLHttp-Initialize.js script file from the blog and run to know the ready state values of AJAX .And also create a txt file of name async.txt and type some text into it.
Ready-State-Values.html
<html>
<script type=”text/javascript” src=”XMLHttp-Initialize.js”></script>
<script type=”text/javascript”>
function process()
{
if(xhr)
{
try
{
xhr.open(“GET”, “async.txt”, true);
xhr.onreadystatechange = handleRequestStateChange;
xhr.send(null);
}
catch(e)
{
alert(“Can’t connect to server:\n” + e.toString());
}
}
}
function handleRequestStateChange()
{
myDiv = document.getElementById(“myDivElement”);
// display the status of the request
if (xhr.readyState == 1)
{
myDiv.innerHTML += “Request status: 1 (loading) <br/>”;
}
else if (xhr.readyState == 2)
{
myDiv.innerHTML += “Request status: 2 (loaded) <br/>”;
}
else if (xhr.readyState == 3)
{
myDiv.innerHTML += “Request status: 3 (interactive) <br/>”;
}
// when readyState is 4, we also read the server response
else if (xhr.readyState == 4)
{
// continue only if HTTP status is “OK”
if (xhr.status == 200)
{
try
{
// read the message from the server
response = xhr.responseText;
// display the message
myDiv.innerHTML += “Request status: 4 (complete). Server said: <br/>”;
myDiv.innerHTML += response;
}
catch(e)
{
alert(“Error reading the response: ” + e.toString());
}
}
else
{
// display status message
alert(“There was a problem retrieving the data:\n” + xmlHttp.statusText);
}
}
}
</script>
<body onload=’process()’>
Hello, server!
<br/>
<div id=”myDivElement” />
</body>
</html>

Hi it was usefull keep rocking dude……..
Pankaj
July 13, 2009 at 1:28 pm