8

I tried to override HTTP request header content by using jQuery's AJAX function. It looks like this

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

btw, is there any good documentation that I can study JavaScript's XMLHttpRequest's encoding handling?

Matt
  • 1,671
  • 5
  • 23
  • 34
  • See http://stackoverflow.com/questions/1145588/cannot-properly-set-the-accept-http-header-with-jquery, a duplicate question to this one. – Jim Ferrans Oct 30 '09 at 05:23
  • @Jim: not really; that other Q is about the Accept header, not about setting the content-type. – Martijn Pieters May 07 '11 at 22:37
  • From the jQuery ajax documentation: Data will always be transmitted to the server using UTF-8 charset; you must decode this appropriately on the server side. http://api.jquery.com/jQuery.ajax/ – Bkress May 20 '11 at 20:50

2 Answers2

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.

Big5 is a subset of UTF-8, right? So it should be possible to encode and decode it server-side.

Edgar
  • 4,348
  • 4
  • 40
  • 59
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

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84