【问题标题】:Encoding sending json to server using jquery使用 jquery 编码将 json 发送到服务器
【发布时间】: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。

【问题讨论】:

标签: jquery json post encoding angularjs


【解决方案1】:

显然问题出在 VRaptor 框架上,它不支持 Accept-Charset 标头。我已经提交了一个补丁,一切都应该没问题。提交的参数编码为 ISO-8859-1,但未按预期解码为 UTF-8。

【讨论】:

    猜你喜欢
    • 2011-05-06
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 2013-12-27
    相关资源
    最近更新 更多