Hi,
From the book: "Foundations of Ajax", page 33, I copied some of the freely-available code into a
JSP page, but it didn't output anything.
The code is below.
Clicking the button, does call the createXMLHttpRequest() method (which for me in FireFox calls the correct object to instantiate), but in the function handleStateChange() the xmlHttp object has value=0 (zero) for both xmlHttp.readyState and for xmlHttp.status.
Any ideas would be greatly appreciated!
-- Mike
================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function startRequest()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange();
xmlHttp.open ("GET", "simpleResponse.xml", true);
xmlHttp.send(null);
}
function handleStateChange()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
alert ("The Server replied with: " + xmlHttp.responseText);
}
}
}
</script>
</head>
<body>
<FORM action="#">
<input type="button" value="Start Basic Async Request"
on_Click="startRequest();"/>
</FORM>
</P>
</body>
</html>
[ March 28, 2006: Message edited by: Bear Bibeault ]