views:

104

answers:

1

Hi, i'm using jQuery for sending ajax requests to the server, but i have some problems with the charset. In the ajax function documentation is written that data is always sent in UTF-8 according to the W3C XMLHTTPRequest standard, so i don't think that jQuery allows you to change the request charset (except if you load a script, but that's not my case).

So do you know a way to set the ISO-8859-1 charset for the ajax request in jQuery?

+1  A: 

I guess this is not possible. You might want to try to override the Content-Type Request header within your ajax call. I tried this with:

$.ajax({
  url: '/exec/seoportservice.pl',
  type: 'POST',
  data: {
     foo: "bar"
  },
  dataType: 'text',
  beforeSend: function(xhr){
    xhr.setRequestHeader('Content-Type', 'test');
  },
  success: function(data){
    console.log('success: ' + data);
  },
});

This actually will override the Content-Type header, but still charset=UTF-8 is set.

So I guess you will have to handle the Encoding serverside.

jAndy