为什么xmlhttp请求不能返回XML类型数据

snowcloud2002 2004-01-04 05:08:09
Data.asp
-----------------------------
<html>
<head>
<script language="JScript">
function PostXML()
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var xmlhttps = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("Post","http://127.0.0.1/xml/GetXML.asp",false);
xmlhttp.Send("");
document.write(xmlhttp.responseXML);
}
</script>
</head>
<body>
<script>
PostXML();
</script>
</body>
</html>
---------------------------
GetXML.asp
----------------------------
<%
Response.Write "<?xml version='1.0' encoding='gb2312' ?>" & vbcrlf
Response.Write "<论坛>" & vbcrlf
Response.Write "<主论坛 id='1' title='Web' XMLSrc='Tree.asp?id=1'>" & vbcrlf
Response.Write "<分论坛 id='1' title='ASP' XMLSrc='ASP.xml'>ASP</分论坛>" & vbcrlf
Response.Write "<分论坛 id='2' title='ASP.Net' XMLSrc='DotNet.xml'>ASP.Net</分论坛>" & vbcrlf
Response.Write "<分论坛 id='3' title='JSP' XMLSrc='JSP.xml'>JSP</分论坛>" & vbcrlf
Response.Write "<分论坛 id='4' title='PHP' XMLSrc='PHP.xml'>PHP</分论坛>" & vbcrlf
Response.Write "<分论坛 id='5' title='CGI' XMLSrc='CGI.xml'>CGI</分论坛>" & vbcrlf
Response.Write "<分论坛 id='6' title='XML|SOAP' XMLSrc='XML.xml'>XML|SOAP</分论坛>" & vbcrlf
Response.Write "</主论坛>" & vbcrlf
Response.Write "</论坛>"
%>

为什么xmlhttp请求不能返回XML数据,输出xmlhttp.responseXML结果为undefined(未定义),请教!
...全文
156 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lex 2004-01-07
  • 打赏
  • 举报
回复
1. 如果转编码以后才能正常读取则说明你的asp文件编码不是GB2312:
<html>
<head>
<script language="JScript">
function streamtochar(bstream){
var stream=new ActiveXObject('ADODB.Stream')
with(stream){
type=1
mode=0
open()
write(bstream)
position=0
type=2
charset="GB2312"
var s=readtext
close()
}
stream=null
return(s)

}
function PostXML(){
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST","http://127.0.0.1/xml/GetXML.asp",false);
xmlhttp.Send();
document.write(streamtochar(xmlhttp.responseBody));
//document.write(xmlhttp.responseXML);
}
</script>
</head>
<body>
<script>
PostXML();
</script>
</body>
</html>

2. 加上(可选):
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<%Reponse.CharSet="GB2312"%>
wuyg719 2004-01-07
  • 打赏
  • 举报
回复
直接用IE打开GetXML.asp看看。
snowcloud2002 2004-01-06
  • 打赏
  • 举报
回复
孟兄,帮忙看看
http://www.8qp8.com/osdn/temp/135.xml?temp=.40993288
Aon 2004-01-05
  • 打赏
  • 举报
回复
你把你要写的XML先写到一个字符串中,然后再一起Response.write,象:

dim str
str="<?xml version='1.0' encoding='gb2312' ?>" & vbcrlf
str = str & "<论坛>" & vbcrlf

......

Response.Write(str)
snowcloud2002 2004-01-04
  • 打赏
  • 举报
回复
不行,提示未定义

xmlhttp.Open("GET","http://127.0.0.1/xml/GetXML.asp",false);
xmlhttp.SetRequestHeader("ContentType","text/xml");
xmlhttp.send("");
Document.Write(xmlhttp.responseXML.xml);

显示undefined
孟子E章 2004-01-04
  • 打赏
  • 举报
回复
xmlhttp.Open("GET","http://127.0.0.1/xml/GetXML.asp",false);
snowcloud2002 2004-01-04
  • 打赏
  • 举报
回复
我加了,不行啊
GetXML.asp
------------------------------
Response.ContentType="text/xml"
加了也不行

zuhuisu 2004-01-04
  • 打赏
  • 举报
回复
GETXML。ASP中要将返回的数据标识为ContentType='text/xml',否则格式为UNDEFINED

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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