Ajax向服务器端发送Xml数据,提示404错误

guolin
博客专家认证
2010-02-15 03:00:43
Ajax向服务器端发送Xml数据,提示404错误,好像是没有找到url地址,我的url是这样定义的 var url="PostingXMLExample?timeStamp=" + new Date().getTime();

使用名为PostingXMLExample.java的Servlet文件进行捕获,但是好像无法捕获到,是不是Servlet文件的放置目录有什么要求,还是其它什么问题。

我的html文件代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</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 createXML(){
var xml="<pets>";
var optional=document.getElementById("petTypes").childNodes;
var option=null;
for(var i=0;i<optional.length;i++){
option=optional[i];
if(option.selected){
xml=xml+"<type>"+option.value+"<\/type>";
}
}
xml=xml+"<\/pets>";
return xml;
}
function sendPetTypes(){
createXMLHttpRequest();
var xml=createXML();
var url="PostingXMLExample?timeStamp=" + new Date().getTime();
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(xml);
}
function handleStateChange(){
if(xmlHttp.readyState==4){
alert(xmlHttp.status);
if(xmlHttp.status==200){
parseResults();
}
}
}
function parseResults(){

var responseDiv=document.getElementById("serverResponse");
if(responseDiv.hasChildNodes()){
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText=document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}
</script>
</head>

<body>
<h1>select the type of pets in your home</h1>
<form action="">
<select id="petTypes" size="6">
<option value="cat">cat</option>
<option value="dog">dog</option>
<option value="fish">fish</option>
<option value="bird">bird</option>
<option value="hamster">hamster</option>
<option value="rabbit">rabbit</option>
</select>
<br /><br />
<input type="button" value="submit pets" onclick="sendPetTypes();" />
</form>
<h2>Server Response</h2>
<div id="serverResponse"></div>
</body>
</html>


...全文
210 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
找不到资源,在仔细看一下路径。
licip 2010-02-17
  • 打赏
  • 举报
回复
404是找不到资源。你看看请求的路径有没有错。
街头小贩 2010-02-16
  • 打赏
  • 举报
回复
注意应用前缀

52,792

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧