谁能帮忙?我有一个小程序可以使用 XMLHttpRequest 读取带有 javascript 的 UTF-8 文件。这个文件有欧洲字符,如 miércoles sábado 等。注意重音..
但是在读入的时候..字符都乱了..我检查了文件,它是完美的..一定是读入的程序..
这是我有一个包含文件的示例,该文件是完美的,它恰好是javascript,但这没关系..任何带有特殊字符的UTF-8编码文件都会给我同样的问题
this.weekDays = new Array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo");
但是当通过下面的过程返回并阅读时,它是这样的(注意 sabado 和 miercoles 中的有趣字符)
this.weekDays = new Array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo");
这是我的程序 - 它非常小......
var contentType = "application/x-www-form-urlencoded; charset=utf-8";
var request = new XMLHttpRequest();
request.open("GET", path, false);
request.setRequestHeader('Content-type', contentType)
if (request.overrideMimeType) request.overrideMimeType(contentType);
try { request.send(null); }
catch (e) { return null; }
if (request.status == 500 || request.status == 404 || request.status == 2 || (request.status == 0 && request.responseText == '')) return null;
//PROBLEM HERE is with european charcters that are read in
print(request.responseText);
return request.responseText;