Skip to content
Advertisement

reading in utf-8 file (javascript XMLHttpRequest) gives bad european characters

can anyone help? I have small procedure to read in an UTF-8 file with javascript using XMLHttpRequest.. this file has european characters like miércoles sábado etc.. Notice the accents..

But when being read in .. the characters are all messed up.. I have checked the file and it is perfect.. it must be the procedure for reading in..

heres an example i have file that contains, the file is perfect, it happens to be javascript but it doesn’t matter.. any UTF-8 encoding file with special characters gives me the same issue

this.weekDays = new Array(“Lunes”, “Martes”, “Miércoles”, “Jueves”, “Viernes”, “Sábado”, “Domingo”);

but when returned and read by the procedure below it is like this (notice the funny characters in sabado and miercoles)

this.weekDays = new Array(“Lunes”, “Martes”, “Miércoles”, “Jueves”, “Viernes”, “Sábado”, “Domingo”);

Here is my procedure – its very small…

JavaScript

Advertisement

Answer

EDIT: Seems that this answer, although accepted, is suboptimal, so for anyone coming here with a similar problem, check out Ricardo’s answer

I think you have to use a different way to print the characters, for example, see the code at the end of this discussion:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement