How to get the AJAX In Place Editor to use ISO-8859-1

When implementing’ AJAX In Place Editor for a project I’m currently working on, I ran into some character encoding problems. My PHP framework uses ISO-8859-1, while the ajax script was submitting UTF-8 to my server. Reading the wiki documentation, I discovered that this was a ‘known feature’:

The form data is sent encoded in UTF-8 regardless of the page encoding.

I was recommended to use iconv to convert back to ISO-8859-1 on the server. Unfortunately this was not an option for me, as it wasn’t available on the production server. Of course, there is PHP’s utf8_decode(), but anyone who has used it will tell you it is totally unreliable.

So, here’s how to get it to use the encoding of your page (e.g. ISO-8859-1) instead of UTF-8. This is based on the info I found in this bug report.

  • Open prototype.js and replace all calls to encodeURIComponent() with escape(). There should be three instances.
  • On the server side, make sure you send all output wrapped with htmlentities(), or else you may experience that the editor ‘hangs’ when updating.

That’s it!

Leave a Reply