【问题标题】:jQuery set ISO charset to ajax requestjQuery 将 ISO 字符集设置为 ajax 请求
【发布时间】:2010-06-16 10:29:44
【问题描述】:

我正在使用 jQuery 向服务器发送 ajax 请求,但我的字符集有一些问题。在ajax 函数文档中写道,根据 W3C XMLHTTPRequest 标准,数据始终以 UTF-8 发送,所以我认为 jQuery 不允许您更改请求字符集(除非您加载脚本,但那是不是我的情况)。

那么你知道在 jQuery 中为 ajax 请求设置 ISO-8859-1 字符集的方法吗?

【问题讨论】:

    标签: jquery ajax utf-8 character-encoding iso-8859-1


    【解决方案1】:

    我想这是不可能的。您可能想尝试在您的ajax 调用中覆盖Content-Type 请求标头。我试过这个:

    $.ajax({
      url: '/exec/seoportservice.pl',
      type: 'POST',
      data: {
         foo: "bar"
      },
      dataType: 'text',
      beforeSend: function(xhr){
        xhr.setRequestHeader('Content-Type', 'test');
      },
      success: function(data){
        console.log('success: ' + data);
      },
    });
    

    这实际上将覆盖 Content-Type 标头,但仍设置了 charset=UTF-8

    所以我猜你将不得不处理编码服务器端。

    【讨论】:

      猜你喜欢
      • 2015-11-22
      • 1970-01-01
      • 2012-09-01
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多