为什么XMLHTTP.responseText返回的中文值全是乱码?

dream520 2004-09-26 05:22:58
代码如下:

<span id="list">读取中……</span>
<script language="javascript">
xml = new ActiveXObject("Microsoft.XMLHTTP");
var post="";//构造要携带的数据
xml.open("POST","http://localhost/index.jsp",false);//使用POST方法打开一个到服务器的连接,以异步方式通信
xml.setrequestheader("content-length",post.length);
xml.setrequestheader("content-type","application/x-www-form-urlencoded");
xml.send(post);//发送数据
var res = xml.responseText;//接收服务器返回的数据
document.getElementById("list").innerText=res;
</script>

结果显示出的数据英文的没问题,中文的全是乱码,而且显示的代码只有原来网页的上半部分,怎么回事?
...全文
976 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssm1226 2004-09-27
  • 打赏
  • 举报
回复
1.可以用Drowning(暑假過完了~~) 给的方法进行转换~
2.可以用楼上的方法,返回XML数据,加入<?xml version='1.0' encoding='gb2312'?>
LiuYongSheng 2004-09-26
  • 打赏
  • 举报
回复
我也遇到这个问题,解决方法如下:
将返回的XML数据的第一行写成:<?xml version="1.0" encoding="gb2312" ?>

你试试看,如果可以就加分!

cleanduo 2004-09-26
  • 打赏
  • 举报
回复
up
Drowning 2004-09-26
  • 打赏
  • 举报
回复
<script language=VBScript>
function getHTTPPage(url)
dim Http
set http=createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = 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
Dim Url,Html
Url="http://www.seasky.biz/"
Html = getHTTPPage(Url)
document.write(Html)
</script>
Drowning 2004-09-26
  • 打赏
  • 举报
回复
谁有完整的adodb.stream代码js的
帮忙帖一下吧
我这只有vbs的
dream520 2004-09-26
  • 打赏
  • 举报
回复
可不可以告诉我怎么做,我不会呀。
dream520 2004-09-26
  • 打赏
  • 举报
回复
在javascript中可以用adodb.stream吗,我查一下。谢谢提醒。
DeltaCat 2004-09-26
  • 打赏
  • 举报
回复
两种方法
一、自己写编码转换函数
二、用 ADODB.STREAM 转换
dream520 2004-09-26
  • 打赏
  • 举报
回复
哦,错了,不是jscript,应该是javascript.
dream520 2004-09-26
  • 打赏
  • 举报
回复
我是说在jscript里如何实现?
DeltaCat 2004-09-26
  • 打赏
  • 举报
回复
在JSP里设置返回的内容为 TEXT/XML, 字符集为 GB2312

87,996

社区成员

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

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