This question already has an answer here:
I have a page which is encoded iso-8959-9. Im sending ajax requests to same page while saving some data to DB. But its converts the chars to utf-8.
My response header seems good with charset iso-8859-9. But the Request Header, Content-Type data always UTF-8. please refer to screenshot below.
Here is what ive done to solve this:
1- I set php header iso-8859-9
2- I changed apache's default charset to iso.
3- i set ajax options beforeSend, setRequestHeader and contentType as iso.
4- i modified jquery.js and set ajax default encoding as iso.
none of them didnt solve my problem. i dont want to do any php charset encoding btw.
Any other ideas ?
Thanks
my ajax code: `
$.ajax({
url: window.location.href,
type: 'POST',
data: $(this).serialize(),
contentType: "application/x-www-form-urlencoded; charset=iso-8859-9",
success: function(result) {
$('#IcerikContent').html($(result).find("#Icerik"));
$('html, body').animate({scrollTop: 0}, 500);
Metronic.initAjax();
if (typeof initialize == 'function') { initialize(); }
stopPageLoading();
}
});
`
I'm afraid that AJAX POST requests must use UTF-8. The jQuery manual explains it:
You might now wonder about the
contentType
setting:In other words, you have no choice. You either need to migrate your server-side code to UTF-8, make an explicit conversion —
iconv()
andmb_convert_encoding()
will come in handy— or figure out a witty JavaScript trick (such as serialising data before submission).