我无法理解如何设置字符集
内容类型不是text / html,text / plain或text / xml,而是application / x-www-form-urlencoded内容类型.
给出这个(简化的)javascript代码:
var xhr = new XMLHttpRequest();
如果我没有明确设置编码,
xhr.open('POST', 'serv.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
萤火虫告诉我内容
type是“application / x-www-form-urlencoded; charset = UTF-8”.
例如,如果我将charset设置为ISO-8859-1,
xhr.open('POST', 'serv.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
firebug仍然告诉我“application / x-www-form-urlencoded; charset = UTF-8.”
如果我尝试类似的东西
xhr.setRequestHeader('Content-Type', 'text/plain; charset=ISO-8859-1');
然后它尊重charset.
在所有情况下,send()方法如下所示:
xhr.send('id=9&name=Yoda');
如果Content-Type是x-www-form-urlencoded,为什么不尊重我指定的charset?
注意:我正在使用ISO-8859-1作为示例.我的目标是了解正在发生的事情.