请教 xmlHttp.responseXML.documentElement取值为空问题

xyy7309 2015-02-15 11:48:02
a.asp 页面

<script>
function showHint(str)
{
var str = str
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200){
//xmlhttp.responseXML.documentElement;
//xmlhttp.responseText;
//xmlHttp.responseXML
var xmlDoc=xmlHttp.responseXML.documentElement;
document.getelementByid("bt").innerHtml=xmlDoc.getelementsBytagname("title")[0].childnodes[0].nodevalue;
document.getelementByid("url").innerHtml=xmlDoc.getelementsBytagname("url")[0].childnodes[0].nodevalue;
}
}
xmlhttp.open("GET","b.asp?q="+str,true);
xmlhttp.setRequestHeader("Content-Type", "text/xml;Charset=UTF-8");
xmlhttp.send();
}
</script>
<input type="text" name="q" id="q" onkeyup="showHint(this.value)">


b.asp 页面

<%
response.Expires=-1
response.contenttype="text/xml"
response.Charset="utf-8"
%>
<%
Dim wid
wid = Trim(Request.QueryString("q"))
%>

<% IF wid<>"" Then%>
<?xml version="1.0" encoding="utf-8" ?>
- <nr_a>
- <nr>
<title>请教大侠 xmlHttp.responseXML.documentElement取值为空问题</title>
<url>http://bbs.csdn.net</url>
</nr>
</nr_a>
<% Else%>
<% response.write "on" %>
<% End If%>


问题:
用xmlHttp.responseXML.documentElement 返回的值是空 null ;
用xmlHttp.responsetext有值返回为字符串(“请教大侠 xmlHttp.responseXML.documentElement取值为空问题http://bbs.csdn.net ”);
用xmlHttp.responseXML 为 [object] ;

[b]请教大侠 如何解决,为感![/size]

...全文
353 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_43183614 2018-09-11
  • 打赏
  • 举报
回复
你好,我也是同样的问题,就是可以获取得到XML文档的DOM对象,但是这个对象的.documentElement根对象却获取不到,为空,这是为什么???你解决了吗
孟子E章 2015-02-16
  • 打赏
  • 举报
回复
现在常用的方法都使用json格式了,xml可以不要使用了
孟子E章 2015-02-16
  • 打赏
  • 举报
回复
既然你使用xml返回,那么if 和else都要返回xml格式才是正确的
孟子E章 2015-02-16
  • 打赏
  • 举报
回复
确保你的代码没有执行到 <% Else%> <% response.write "on" %> <% End If%> 这个分支上去。
xyy7309 2015-02-16
  • 打赏
  • 举报
回复
引用 1 楼 slwsss 的回复:
http://bbs.csdn.net/topics/390986973#post-398907674
- <nr_a>
- <nr>
“横线”去掉


“横线”去掉,那不是什么“横线”,是XML输出格式自动的,点击”-“收缩。

slwsss 2015-02-16
  • 打赏
  • 举报
回复
http://bbs.csdn.net/topics/390986973#post-398907674 - <nr_a> - <nr> “横线”去掉
xyy7309 2015-02-16
  • 打赏
  • 举报
回复
引用 3 楼 net_lover 的回复:
确保你的代码没有执行到 <% Else%> <% response.write "on" %> <% End If%> 这个分支上去。
你好,孟子E章 , 同样的内容,xml文件可以获取,asp文件获取unll

52,797

社区成员

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

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