首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎的解决乱码 ajax

2011-12-26 
怎样解决乱码 ajaxscript languagejavascriptvar xmlhttpxmlhttp new ActiveXObject(Microsoft.X

怎样解决乱码 ajax
<script language="javascript">
var xmlhttp;
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("get","test.xml");
xmlhttp.setRequestHeader("Content-Type","text/xml");
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readystate==4)
{
if(xmlhttp.status==200)
{
var xmlobj=xmlhttp.responseText;
//alert(xmlobj);
document.getElementById("xml").value = xmlobj;
}
else
{
alert("sdf");
}
}
}
xmlhttp.send(null);
</script>


我用Ajax把test.xml中的内容提取到我的本地,但是问什么返回的内容中,中文显示不出来,返回的是乱码。大家给解决一下吧。

[解决办法]
检查使用这段js页面的编码和你的xml声明中的编码是否一致

还有你点就是既然是取xml文件,你最好分析xml取内容(responseXML)


if(xmlhttp.readystate==4) 

==>
if(xmlhttp.readyState==4)
[解决办法]
我直接返回xml里的内容时,没有乱码啊....再检查下你的编码...

热点排行