2
I created a Servlet q returns a simple JSON. I was able to consume it quietly, but by putting the content in a div
was as follows:
0: �gua
1: a�ucar
2: sal
3: canela
4: �leo
Looking at the return of Servlet from the Chrome network tab I saw that JSON came with the encoding correct, follow the return:
[{Item: "água"}, {Item: "açucar"}, {Item: "sal"}, {Item: "canela"}, {Item: "óleo"}]
I realized the problem is only in ajax, so how do I solve this problem?
I tried several solutions and nothing I found on the net solved, I put meta tag (actually changed, because I already had), I put contentType
and encoding
in ajax and nothing.
Follow my code (already tried with UTF-8, ISO and finally Windows):
$.ajax({
url: '',
data: 'POST',
dataType: 'json',
encoding:"Windows-1252",
contentType: "text/plain; charset=Windows-1252"
}).done(function(retorno){
alert(retorno);
var k = 0;
$.each(retorno, function(i, item){
criarElemento("<p>", {html: i+": "+item.Item, id: 'item_'+k}, "teste");
k++;
});
});
Things I would try: 1. Open Veloper tools, open tab
Network
and save the ajax. See the content-type of the request if it is the same as you are passing. 2. goes in your editor, with the page Servet opened and goes in "save as" and chooses UTF-8. Only the meta-description encoding sometimes does not. If you have JS files you also save them as UTF. You would also test without these 1252 encodings on.ajax
from JSON. It’s always easier to be all UTF.– Michelle Akemi