Side navigation
#6645 closed bug (wontfix)
Opened June 08, 2010 03:09AM UTC
Closed October 19, 2010 08:09PM UTC
Last modified March 13, 2012 08:28PM UTC
Unable to set ajax Request charset header
Reported by: | Nepherim | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.4.3 |
Component: | ajax | Version: | 1.4.2 |
Keywords: | charset | Cc: | |
Blocked by: | Blocking: |
Description
It appears that it is not possible to set the Ajax Request Content-Type charset. The default is UTF8, regardless of other Charset, or HTML META settings.
Attachments (0)
Change History (6)
Changed June 11, 2010 02:53AM UTC by comment:1
resolution: | → worksforme |
---|---|
status: | new → closed |
Changed June 12, 2010 03:18PM UTC by comment:2
resolution: | worksforme |
---|---|
status: | closed → reopened |
I'm not familiar enough with the spec to comment on it with authority, but would make the following points:
1] It seems quite unclear to me that making an assertion based on taking that single line on it's own is valid. Reading the entire part of the spec it at least seems open to interpretation of allowing other charsets.
2] Forcing all Requests to UTF8, has significant impact for anyone not already using that charset, particularly since that enforcement does not carry through to any other component of the the html/javascript/back-end platform stack.
3] It *seems* like setRequestHeader() http://www.w3.org/TR/XMLHttpRequest/#setrequestheader allows the charset to be set.
4] At the very least, if *forced* conversion to UTF8 is the approach, then either force this behavior throughout (very poor option), or document the behavior clearly.
Changed June 12, 2010 04:10PM UTC by comment:3
This doesn't seem to be a jQuery issue, it's related to the underlying XMLHTTPRequest object. Just find some references to pages showing how it can be done with the bare XMLHTTPRequest object and we'll see if we can get it into jQuery. If not I'll close the ticket since it's not in control of jQuery.
Since you're making the request, I was hoping you'd do the legwork to prove that it was allowed and that other people had done it. In replying to the original request I searched around for about half an hour and didn't find anything definitive.
Changed June 13, 2010 07:22PM UTC by comment:4
It looks like you are correct, although information is very conflicting. From experimenting it does not seem to be possible to override the charset from setRequestHeader -- it's always UTF-8. The most popular approaches are below, but these, along with many other approaches fail to actually change the charset.
xhr.overrideMimeType("text/html; charset=ISO-8859-1");
xhr.setRequestHeader("Accept-Charset", "ISO-8859-1");
There are various anecdotal references indicating that javascript uses Unicode internally, and transforms that to UTF-8 for transmission to the server (ie, http://stackoverflow.com/questions/919936/does-javascript-force-specific-charset). However, I was unable to unearth any authoritative source for this.
So, it seems that it's not possible to force the Request header to a non-UTF-8 charset, and this ticket can be closed. It would be nice to have some specific reference, or source for this though, other than me being unable to find anything.
Understanding this is not a jQuery issue specifically, could the documentation be updated to reflect this behavior. Something like:
"It is possible to set the document Content-Type using the contentType parameter, but it is not possible to set the Charset for the Request header. Data will always be transmitted to the server using UTF-8 charset; you must decode this appropriately on the server side if you are not using UTF-8."
Changed October 19, 2010 08:09PM UTC by comment:5
priority: | → low |
---|---|
resolution: | → wontfix |
status: | reopened → closed |
As we have agreed this is not a jQuery issue, I've added this ticket and the documentation changes requested to a docs review sheet. Closing as there is nothing further that can be done here.
Changed February 06, 2012 03:40PM UTC by comment:6
Relevant: http://hsivonen.iki.fi/accept-charset/
True, but I believe this is according to the XMLHttpRequest standard.
"Otherwise, let encoding be UTF-8, mime be text/plain, and then follow these rules: ..."
http://www.w3.org/TR/XMLHttpRequest/#send
If I have interpreted that incorrectly, reopen the ticket with an explanation and pointer to some ways to override UTF-8.
See also #3611 .