【发布时间】:2013-05-11 19:10:06
【问题描述】:
我正在尝试使用 jQuery 将 json 数据发送到服务器,但服务器上的每个拉丁字符都是错误的。我已经将所有内容都放入了 utf-8 字符集。字符在请求的那一刻被改变。如果我发送类似ç 的内容,它会以√ß 的形式到达。这是我的方法:
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. };
02 行打印:
json: {"atendimento":{"chegada":"11/05/2013 15:49:00","paciente":"ç","procedimento":"ç","observacoes":"ç","agendado":false}}
但是,这是发送到服务器的内容:
{"atendimento":{"chegada":"11/05/2013 15:49:00","paciente":"ç","procedimento":"ç","observacoes":"ç","agendado":false}}
这是收到的:
{"atendimento":{"chegada":"11/05/2013 15:49:00","paciente":"ç","procedimento":"ç","observacoes":"ç","agendado":false}}
我在客户端使用 angularJs 和 jQuery,在服务器使用 VRaptor。
【问题讨论】:
-
您是否将文件保存为 UTF8 ?
-
在发送之前尝试对字符串进行编码 [stackoverflow.com/a/2130775/336542][1] [1]: stackoverflow.com/a/2130775/336542
标签: jquery json post encoding angularjs