XMLHTTP 乱码的解决方法(UTF8,GB2312 编码 解码)(2)


var obj=document.getElementById(oid);
obj.style.display="block";
obj.focus();
if(obj.innerHTML!="")return;
tree=new dhtmlXTreeObject(oid,"100%","100%",0);
tree.setImagePath("js/imgs/csh_vista/");
tree.setOnClickHandler(click1);
tree.setXMLAutoLoading("tree.asp");
//load first level of tree
tree.loadXML("tree.asp?id=0");


tree.asp编码为gb2312,和整个系统一致,用response.write返回一个xml
整个系统编码改不了,只有在DHTMLX上想办法了。
查了些资料,最终解决了。


再深入一层发现是,Microsoft.XMLHTTP的原因,就查到了上面的文件。
如是就简单了,修改如下:
1. 增加一个VBScript的中文转换的函数

复制代码 代码如下:


<script language="VBScript">
'处理中文
function bin2str(bin)
dim tmp,ustr,i
tmp=""
for i=1 to LenB(bin)-1
ustr=AscB(MidB(bin,i,1))
if ustr>127 then
i=i+1
tmp=tmp&chr(ustr*256+AscB(MidB(bin,i,1)))
else
tmp=tmp&chr(ustr)
end if
next
bin2str=tmp
end function
</script>


2.dhtmlxcommon.js的 getXMLTopNode处
var xmlString = this.xmlDoc.responseText;
改为
var xmlString = bin2str(this.xmlDoc.responseBody);//可以在js里直接调用VBScript脚本

3.同时 在输出xml的asp 文件开头加入
<%response.ContentType="application/xml"%>
<?xml version='1.0' encoding='GB2312'?>
当然文件也是保存为gb2312格式的。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdffps.html