• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't get first example to work

 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book Foundations of Ajax, I can't get the first example on page 33 to work.

From the code below, I get the following output:

"The Server's ready state is 1"
Click the button again and get...
"The Server's ready state is 1"
Click the button again and get...
"The Server's ready state is 2"
Click the button again and get...
"The Server's ready state is 3"
Click the button again and get...
"The Server's xmlhttp.status is 404".

What's wrong? No status 200. I'm using Tomcat 5.5.

Thanks in advance.

- Mike

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<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.status);
}
else
{
alert("The Server's xmlHttp.status is: " + xmlHttp.status);
}
}
else
{
alert ("The Server's ready state is: " + xmlHttp.readyState);
}
}
</script>

</head>

<body>
<FORM action="#">
<input type="button" value="Start Basic Async Request"
(The click code calls startRequest() logic )
</FORM>
</body>
</html>
[ September 22, 2006: Message edited by: Bear Bibeault ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the XML file in the same directory as this page?

Eric
 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought the XML file came back from the server. On the bottom of page 33 it says that the Server's response file, SimpleResponse.xml, has only a single line of text.

Do I need to create that file?

I'm not sure what I missed.

Thanks in advance for your help on this.

-- Mike
 
Mike London
Ranch Hand
Posts: 1185
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out. Thanks Eric for your help.

Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic