Question

I'm trying to send json data to a server using jQuery but every latin character is wrong at the server. I've already put everything to utf-8 charset. The characters get changed on the moment of the request. If I send something like ç it arrives as √ß. Here is my method:

01. function(atendimento, success) {
02.     var json = JSON.stringify({atendimento: atendimento});
03.     console.log('json: ', json);
04.     $.ajax({
05.         url: '/atendimentos/',
06.         data: json,
07.         contentType: 'application/json; charset=utf-8',
08.         dataType: "json",
09.         type: 'POST',
10.         success: function() {
11.             self.atendimentos.unshift(atendimento);
12.             success();                  
13.         }
14.      });
15.    };

line 02 prints:

json:  {"atendimento":{"chegada":"11/05/2013 15:49:00","paciente":"ç","procedimento":"ç","observacoes":"ç","agendado":false}}

However, this is what is sent to the server:

{"atendimento":{"chegada":"11/05/2013 15:49:00","paciente":"ç","procedimento":"ç","observacoes":"ç","agendado":false}}

And this is what is received:

{"atendimento":{"chegada":"11/05/2013 15:49:00","paciente":"ç","procedimento":"ç","observacoes":"ç","agendado":false}}

I'm using angularJs and jQuery on the client and VRaptor on the server.

Was it helpful?

Solution

Apparently the issue was with VRaptor framework that wasn't honoring the Accept-Charset Header. I've already submited a patch and everything should be fine. The parameter was submited encoded as ISO-8859-1 and wasn't decoded as UTF-8 as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top