Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't change HTTP request header Content-Type value using jQuery

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?

like image 992
Matt Avatar asked Oct 30 '09 04:10

Matt


1 Answers

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.

like image 199
Edgar Avatar answered Oct 24 '22 14:10

Edgar