Monday, February 6th, 2006
AJAX and Multibyte Character Support
Taylan Pince has a post on his blog that looks at an issue several don’t think about when developing pages/applications with Ajax – multibyte caharacter support.
I love AJAX, and I realize that there are more than enough tutorials on the subject floating around the web these days (my favourite is still the one over at the Apple Developer Connection). But when I wanted to use a simple AJAX menu for a site I was developing in Turkish, I quickly realized that there are some issues about character encoding in dynamically loaded AJAX elements, and that there are no apparent solutions.
He creates a solution in a few simple lines of code to make the script the Ajax connection calls use a properly formatted UTF-8 content type. The code is there to take advantage of, as well as a simple function-based usage method he suggests.












javascript’s ecape() and unecape() may help it out
sorry ;-)
they are escape() and unescape()
In perl the easiest is of course:
—
use HTML::Entities;# and later...
print encode_entities($output);
—
and $output is html encoded.
Remember, escape() and friends aren’t the solution. The solution is to know your data and output it in the correct encoding. The correct encoding being UTF-8, unless you have very good reasons otherwise.
Dominic,
May I ask why escape isn’t an acceptable solution. I have been using this soltution a while and it even solves problems concering characters in languages such as russian and greek (non-western character set).
Best regards,
hbi
Hakan.. I believe escape is deprecated in the ECMA3 spec. The recommended method is encodeURIComponent(), which encodes in UTF-8.
(supported since Netscape 6/IE 5.5)