YUI AJAX tries to get along, but sometimes that’s a bad thing. In particular when it comes to € (Euro) symbols.

At youDevise, we currently have our TIM pages encoded to the charset of ‘ISO-8859-15’ as opposed to the largely adopted and recommended ‘UTF-8’. This has allowed us to keep certain parts of our application compatible with some older systems still in use at our clients. Despite staying old-school in our page encoding, our systems have been working just fine with submitting extended charset characters such as the Euro symbol.

More recently however, we’ve introduced some new functionality which we’ve enabled using the excellent Yahoo User Interface javascript library, in particular we’ve been using it for AJAX calls.

Unfortunately, over AJAX the rules are a bit different, and those extended characters that played so well over a normal POST method were becoming garbled over an AJAX submit. After a bit of digging I determined that what was going on was that the YUI Connection Manager was simply being too nice for our own good and adopting the same ISO-8859-15 encoding for its submissions to the server that our normal pages use.

I’m afraid the normally quite excellent documentation on the YUI let me down a bit this time, but I was able to find a simple fix to make our AJAX calls use the UTF-8 encoding. Using the Connection Manager’s initHeader method I can set the encoding to UTF-8, avoiding the garbling!

YAHOO.util.Connect.initHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
YAHOO.util.Connect.asyncRequest("POST",....);

Leave a Reply

Your email address will not be published. Required fields are marked *