I am having problem displaying accented character in my app; It is showing ⛽ instead of ó. The string is coming from a json file retrieved from a server. Here are the technical details:
JSON: (This is the object being retrieved from the server)
notice the 3rd key "Relación" the letter "o" is accented.
[
{
"key": "Canales"
},
{
"key": "Productos"
},
{
"key": "Relación con el ejecutivo"
}
]
Ajax (here is the code to retrieve the information)
notice I already added charset=utf-8 as most answers suggest
$.ajax({
url: url,
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(uri){
alert("clintg test: " + JSON.stringify(uri));
}
}
Alert: (as you can see, it is just showing a box symbol where it's supposed to be -> ó)
To give more detail to @georg 's advice that helped me solve this issue:
Since I can't change the server side scripts, I adjusted the code on my side.
I changed the charset in my ajax request to ISO-8859-1, but since the default charset of ajax is utf-8, I had to override the charset with $.ajax.beforeSend
:
$.ajax({
url: url,
type: "GET",
dataType: "json",
contentType: "application/json; charset=iso-8859-1",
success: function(uri){
alert("clintg test: " + JSON.stringify(uri));
},
beforeSend: function(jqXHR) {
jqXHR.overrideMimeType('application/json;charset=iso-8859-1');
}
}
Here's a link to the question that helped me figure out and override the charset: Jquery ignores encoding ISO-8859-1
来源:https://stackoverflow.com/questions/26884747/displaying-accented-character-in-javascript