Who's responsible for this wrong encoding?

2019-08-10 05:31发布

问题:

I have a HTML file with a javascript. The javascript reads a local ISO-8859-1 CSV file through AJAX. I have declared three times that I'm working with ISO-8859-1, and still the rendering is wrong, showing that black square with a '?' inside. What am I doing wrong? I don't know what else to try...

Not sure if this is important, but the text I am trying to print show is the title in a google.maps.Marker. Maybe it HAS to be utf-8? Maybe there's no way but to convert the string to UTF-8 first?

The AJAX reading function in the javascript:

function loadlocalcsv(file) {
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.open("GET", file, true);
  xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  xmlHttp.addEventListener("load", ajaxCallback, false);
  xmlHttp.send(null);
}
function ajaxCallback(event){
  var csv = event.target.responseText;
  processData(csv);
}

The HTML file has this metadata:

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>

and the javascript is called with this:

<script type="text/javascript" charset="ISO-8859-1" src="mymap.js"></script>

Thanks!