| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1441 人关注过本帖
标题:Error:没有对象,帮忙看看,谢谢
取消只看楼主 加入收藏
yexin218
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-12-5
结帖率:100%
收藏
 问题点数:0 回复次数:1 
Error:没有对象,帮忙看看,谢谢
servlet CODE:

httpServletResponse.setContentType("text/xml; charset=UTF-8");
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"<songaddr>"+this.getSongAddr()+"</songaddr>"+"<wordaddr>"+this.getWordAddr()+"</wordaddr>";
System.out.println("*******************\n");
System.out.println(content);
System.out.println("*******************\n");
httpServletResponse.getWriter( ).write(content);

从servlet返回的xml结果是:
<?xml version="1.0" encoding="UTF-8"?>
<songaddr>http://202.38.64.71:8099/英文/Al
l_Saints/Saints_And_Sinners/daSYlaKpNw$$.mp3</songaddr>
<wordaddr>40369</wordaddr>

然后到js文件中


CODE:
window.onload = function(){
document.getElementById("songsearch").onclick=function(){
var _song= document.getElementById("song");
var _singer=document.getElementById("singer");
if(_song.value){
getSong(_song.value,_singer.value);
}

};
//defualt value
//getSong("等一分钟","");
};
function getSong(song,singer){
if(song == null){
document.getElementById("song").value="";
//return ;
}else{
var url = "http://localhost:8080/baidusongs/songsearch?song="+encodeURIComponent(song)+"&singer="+encodeURIComponent(singer);
httpRequest("GET",url,true,handleResponse);
}
}

function eMsg(msg,sColor){
var div = document.getElementById("addr_song");
div.style.color=sColor;
div.style.fontSize="0.9em";
//remove old messages
if(div.hasChildNodes()){
div.removeChild(div.firstChild);
}
div.appendChild(document.createTextNode(msg));

}
function handleResponse(){
var xmlReturnVal;
try{
if(request.readyState == 4){
if(request.status == 200){
xmlReturnVal=request.responseXML;
if(xmlReturnVal != null) {
var addr_song = xmlReturnVal.getElementsByTagName("songaddr")[0];
//var addr_song_val = addr_song.childNodes[0].data;
//eMsg(addr_song_val,"red");
addr_word = xmlReturnVal.getElementsByTagName("wordaddr")[0];
if(addr_song){
eMsg(addr_song.childNodes[0].data,"red");

//document.getElementById("addr_song").value= addr_song.chileNodes[0].data;
}
if(addr_word){
eMsg(addr_word.chileNodes[0].data,"red");
//document.getElementById("addr_word").value= addr_word.chileNodes[0].data;
}
}
}else{
alert(
"A problem occurred with communicating between"+
" the XMLHttpRequest object and the server program.");
}
}
}catch (err) {
alert("It does not appear that the server "+
"is available for this application. Please"+
" try again very soon. \nError: "+err.message);

}
}

前台html

[Copy to clipboard] [ - ]
CODE:
<body>
<h3>Input the name of song and singer</h3>
<form action="javascript:void%200" method="get">
<p>
Name of Song: <input type="text" id="song" name=
"song_name" size="20" maxlength="20" />
</p>
<p>
Name of Singer: <input type="text" id="singer" name=
"singer_value" size="20" maxlength="20" />
</p>
<p>
<div id="addr_song"></div>
<!--<div id="addr_word"></div>-->

</p>
<p>
<button id="songsearch" type="button">Search</button>
</p>
</form>

可是就是没有反应。
原因可能在



if(xmlReturnVal != null) {

var addr_song = xmlReturnVal.getElementsByTagName("songaddr")[0];

//var addr_song_val = addr_song.childNodes[0].data;

//eMsg(addr_song_val,"red");

addr_word = xmlReturnVal.getElementsByTagName("wordaddr")[0];


有时候会出现没有对象的错误!
帮忙看看,错在什么地方了?
谢谢!

[此贴子已经被作者于2007-8-15 21:24:14编辑过]

搜索更多相关主题的帖子: 对象 
2007-08-15 21:17
yexin218
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-12-5
收藏
得分:0 
哦,ip方式指?

2007-08-17 12:19
快速回复:Error:没有对象,帮忙看看,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024889 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved