I tried to override HTTP request header content by using jQuery's AJAX function. It looks like this
我尝试使用jQuery的AJAX函数覆盖HTTP请求标头内容。看起来像这样
$.ajax({
type : "POST",
url : url,
data : data,
contentType: "application/x-www-form-urlencoded;charset=big5",
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept-Charset","big5");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=big5");
},
success: function(rs) {
target.html(rs);
}
});
Content-Type header is default to "application/x-www-form-urlencoded; charset=UTF-8", but it obviously I can't override its value no matter I use 'contentType' or 'beforeSend' approaches. Could anyone adivse me a hint that how do I or can I change the HTTP request's content-type value? thanks a lot.
Content-Type标头默认为“application / x-www-form-urlencoded; charset = UTF-8”,但显然无论我使用'contentType'还是'beforeSend'方法,我都无法覆盖它的值。任何人都可以向我提示我如何更改HTTP请求的内容类型值?非常感谢。
btw, is there any good documentation that I can study JavaScript's XMLHttpRequest's encoding handling?
顺便说一下,有什么好的文档可以研究JavaScript的XMLHttpRequest的编码处理吗?
2 个解决方案
#1
2
According to the jQuery docs, charset will always be UTF-8: http://jqapi.com/#p=jQuery.ajax. I guess the same goes for accept-charset.
根据jQuery文档,charset将始终是UTF-8:http://jqapi.com/#p=jQuery.ajax。我猜对于accept-charset也是如此。
Big5 is a subset of UTF-8, right? So it should be possible to encode and decode it server-side.
Big5是UTF-8的子集,对吧?因此应该可以对服务器端进行编码和解码。
#2
0
Have you checked the w3.org documentation? There appears to be some limitation in using Accept-Charset
header. http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method
你查过w3.org文档了吗?使用Accept-Charset标头似乎有一些限制。 http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method
#1
2
According to the jQuery docs, charset will always be UTF-8: http://jqapi.com/#p=jQuery.ajax. I guess the same goes for accept-charset.
根据jQuery文档,charset将始终是UTF-8:http://jqapi.com/#p=jQuery.ajax。我猜对于accept-charset也是如此。
Big5 is a subset of UTF-8, right? So it should be possible to encode and decode it server-side.
Big5是UTF-8的子集,对吧?因此应该可以对服务器端进行编码和解码。
#2
0
Have you checked the w3.org documentation? There appears to be some limitation in using Accept-Charset
header. http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method
你查过w3.org文档了吗?使用Accept-Charset标头似乎有一些限制。 http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method