1

I need to send data to the server using the character set Big-5, however the browser seems to only encode the data in UTF-8. If I were to make a form, then it can be achieveable with the following attribute:

<form accept-charset="Big5">

However, I want to send the data through XHR. Some answers suggest that contentType can let me change it. But according to jQuery's documentation, the encoding cannot be overridden: (at least this is true in Chrome.)

The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding.

$.ajax({
    url: "dummy url",
    type: "GET",
    data: {
        q: "Test"
    },
    contentType: "application/x-www-form-urlencoded;charset=Big5"
}, function(){});
//This won't work.

Is there any way to get around it?

Community
  • 1
  • 1
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
  • You do change it with contentType like you're doing. If you control the other server, it shouldn't be a problem. – NewInTheBusiness Jan 17 '14 at 00:13
  • @NewInTheBusiness - The problem is I don't have control over it. I just want to send some data across and fetch back the returned data, however it requires the parameters to be in that charset. And setting `contentType` doesn't help. – Derek 朕會功夫 Jan 17 '14 at 00:16
  • I think ajax defaults to utf8 – Alex Shilman Jan 17 '14 at 00:18
  • @AlexShilman - Yes indeed (I mentioned it in my question, actually.) – Derek 朕會功夫 Jan 17 '14 at 00:19
  • According to this **[SO post](http://stackoverflow.com/questions/553463/jquery-ajax-character-encoding-problem)** you have to change the charset, as you're doing, but it also needs to be specified on the server – jasonscript Jan 17 '14 at 02:49

0 Answers0