File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Can't get first example to work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can Watch "Can New topic
Author

Can't get first example to work

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
You have the XML file in the same directory as this page?

Eric
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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

Joined: Jul 12, 2002
Posts: 1034
Figured it out. Thanks Eric for your help.

Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't get first example to work
 
Similar Threads
passing xml to jsp/java
Simple Ajax example doesn't work
JavaScript not working in IE7 but working in firefox
Ajax + struts
JSF1.2 Core+AJAX+Portlets getting problematic while constructing the url