我试图在我的 ajax 请求 header 上强制使用“ISO-8859-1”字符集,但出于某种原因我无法将其从“UTF-8”更改。我有以下...
var request = new Request({
url: url,
method: 'post',
data: params,
encoding: 'ISO-8859-1',
onSuccess: function(textResponse, xmlResponse) {
//success func
},
onFailure: function(xhr) {
//fail func
}
}).send();
即使在配置该设置之后,我的请求 header 的内容类型在 Chrome 的开发人员工具中显示“application/x-www-form-urlencoded; charset=UTF-8”。
有什么想法吗?
最佳答案
它确实有效。 1 个小问题:设置字符集的代码路径在另一个变量后面 - urlEncoded: true
需要设置。
参见 https://github.com/mootools/mootools-core/blob/master/Source/Request/Request.js#L175-L178
和一个 jsfiddle 来演示这个:http://jsfiddle.net/dimitar/3qazx/
new Request({
url: '/echo/html/',
data: {
html: '<p>Text echoed back to request</p>',
delay: 0
},
method: 'post',
urlEncoded: true,
encoding: 'ISO-8859-1',
onComplete: function(){
$('target').set('html', this.response.text);
}
}).send();
我认为文档不清楚两者之间的关系 - http://mootools.net/docs/core/Request/Request#Request
它说了,但是嗯:
urlEncoded
- (boolean
: defaults to true) If set to true, thecontent-type
header is set towww-form-urlencoded
+encoding
encoding
- (string: defaults toutf-8
) The encoding to be set in the request header.
后者需要“当 urlEncoded 不正确时被忽略”
关于javascript - Mootools 1.4.5 请求 'encoding' 选项不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23665090/