关于XMLHTTP的问题

天空中国 2005-12-12 12:44:08

<%
On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function

Function GetBody(url)
on error resume next
Set Retrieval = server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.setHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function

Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>
<%

url="http://192.168.0.6/chat/chat/refresh1.asp"
wstr=getHTTPPage(url)


%>

<script language="javascript">
function doloop()
{
document.write("111111");
document.write("<%response.write wstr%>");
setTimeout("doloop()",1000);
}
doloop();
</script>
wstr是通过XMLHTTP获得的,但是老是显示不出来,包括字符串"111111"都不能显示,
如果去掉 document.write("<%response.write wstr%>"); 能显示"111111",
这是为什么,通过XMLHTTP获得的数据怎么在JAVASCRIPT里显示啊,
...全文
141 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueonly 2005-12-13
  • 打赏
  • 举报
回复
先查看asp生成html和script是否正确
天空中国 2005-12-13
  • 打赏
  • 举报
回复
我已经搞好了,谢谢大家
sosinoe 2005-12-12
  • 打赏
  • 举报
回复
function XMLHTTPButton_onclick() {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST","http://localhost/test.asp",false);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(DataToSend);
alert(xmlhttp.responseXML.xml);
}
创造奇迹9999 2005-12-12
  • 打赏
  • 举报
回复
用alert测试一下你获取到了数据没有

还有就是你把getHTTPPage申请成一个全局变量试试,

为什么要用JAVASCRIPT往出写值呢?为什么不直接用ASP写?

或者直接在javascript里面用xmlhttp获取数据也可以,
hyq8848 2005-12-12
  • 打赏
  • 举报
回复
你把getbody 换成gettext
文本显示

Function GetBody(url)
on error resume next
Set Retrieval = server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.setHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
.Send
GetBody = .Responsetext
End With
Set Retrieval = Nothing
End Function
天空中国 2005-12-12
  • 打赏
  • 举报
回复
改成它后,GetBody = .Responsetext 所有的中文都不能显示了,
天空中国 2005-12-12
  • 打赏
  • 举报
回复
去掉下面的JS代码,直接输出RESPONSE.WRITE wstr 就可以了,但不能即时更新
天空中国 2005-12-12
  • 打赏
  • 举报
回复
我是想做一个无刷新的聊天室,在refresh1.asp中显示了聊天对话的信息,然后我想通过XMLHTTP把refresh1.asp中的信息取出来显示,就可以避免刷新,但是我对JS不太了解,所以请大侠们帮帮忙!!

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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