Search code examples
jqueryloadcharspolish

JQuery load() and national letters(like ę,ą,ć)


I'm using JQuery load() method to load content to page. The only problem is, when content is loaded via load() method all national(polish) chars are displaying invalid... On both pages loaded and main(in which content is load) coding is set to iso-8859-2(yeah, I know, I should use utf-8 bo it doesn't help in this case).

I don't really know how to solve it. The only solution I though of is replacing special chars with some code before loaded and after receiving data decoding it, but it's kind of complicated:D

Any ideas?

Cheers


Solution

  • Ok, I did some research. And this is what I found:

    jQuery .load() does not look into HTML meta tag for content-type. You can choose one of two options:

    1. To set HTTP response headers to Content-type: text/html; charset=iso-8859-2 and then use jQuery .load(). For instance in PHP you can do it by putting this at the top of the page:

      <?php header('Content-type: text/html; charset=iso-8859-2'); ?>

    2. To override HTTP response content type on client side using jQuery. For this purpose you should pass the setting mimeType: "text/html; charset=iso-8859-2" to $.ajax(). You can't do this using .load() because it does not support the ability to set ajax settings.

    Both options tested, so everything should work! :)