I created a servlet that returns a simple JSON. I was able to consume the same quietly, however putting the contents in a div
was as follows:
0: �gua
1: a�ucar
2: sal
3: canela
4: �leo
When looking at the return of the servlet through the Chrome network tab, I saw that JSON came with the correct encoding , follow the return:
[{Item: "água"}, {Item: "açucar"}, {Item: "sal"}, {Item: "canela"}, {Item: "óleo"}]
I noticed that 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 (I actually changed it, because I already had it), I put contentType
and encoding
in ajax and nothing.
Here's my code (I've already tried 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++;
});
});