Hello i am trying to create a开发者_运维知识库 document using Javascript and there's a problem with the encoding of the document, because reject all the non-ascii characters, the string that im passing is this "verificación" but is replaced with this "�", how i can fixed that.
This is my code:
function createDoc(string){
if (window.DOMParser)
{
parser = new DOMParser();
doc = parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+string, "text/xml");
}
else // Internet Explorer
{
doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
doc.loadXML('<?xml version="1.0" encoding="UTF-8"?>'+string);
}
return doc
}
Thanks in advance.
Javascript strings are all UTF-16-encoded. You could try specifying that.
Where does the string come from? Is the string correct before parsing it?
Also, when is it being displayed? What encoding is expected there?
精彩评论