Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#6645 closed bug (wontfix)

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.

Ref: http://solidgone.com/jquery/ajax_charset_test.html

Change History (6)

comment:1 Changed 10 years ago by dmethvin

Resolution: worksforme
Status: newclosed

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 .

comment:2 Changed 9 years ago by Nepherim

Resolution: worksforme
Status: closedreopened

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.

comment:3 Changed 9 years ago by dmethvin

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.

comment:4 Changed 9 years ago by Nepherim

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."

comment:5 Changed 9 years ago by addyosmani

Priority: low
Resolution: wontfix
Status: reopenedclosed

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.

Note: See TracTickets for help on using tickets.