用MSXML2.XMLHttp加载带中文的XML文件,responseXML.xml = '',强制加载报错“Switch from current encoding to specified encoding not supported”
mzhao 2008-07-07 04:46:11 我用javascript写了一个AJAX的Htc文件,调试时发现XmlHttp.responseXML一直没有内容(即responseXML.xml = ''),parseError=0。
后来我试着用alert(XmlHttp.responseText);发现内容中的中文都变成了'?'.
我又试了试使用以下代码:
var body = XmlHttp.responseXML;
body.loadXML(XmlHttp.responseText);
alert(body.parseError);
alert(body.parseError.reason);
提示:-1072896657;Switch from current encoding to specified encoding not supported
看起来是编码不对。
我又试着将XML文件改成utf-8格式的英文文件,同样报错。
不知是XmlHttp的bug还是我写的代码有问题,但是我没有发现XmlHttp加载时能设置charset呀?
我用的是IE7.0,加载任何其他带中文的Ajax页面都没问题。
注:1、不要让我使用setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded "); ,我试过,不管用
2、不要让我使用Microsoft.XMLDOM,应为我原来的程序就是用它的(没有以上错误),可到了IE7以后不被支持了。