Problems with UTF-8 and AJAX...

Hey :slight_smile:

I have an AJAX tree to manage pages in a CMS-like manner. The leaves can be clicked to expand an editor which allows the backend admin to alter settings, set page titles, add content, etc. The site's primary language is Danish, so we have a lot of æ, ø, and å characters.

If I got into the backend pages administration module and render the tree, these special characters are rendered correctly, so that all visible leaves with æ, ø, or å in them show these special characters correctly. The page information tab in the Web Developer plugin for Firefox show content encoding to be UTF-8 for both the response header and the document encoding.

If i then click a leaf to expand it, an AJAX call is made to render a partial in which I get a form with fields that will allow me to edit titles and texts, among other things. Still, æ, ø, and å are displayed correctly.

If I then submit the form, again via AJAX, the data is saved correctly (I can confirm that æ, ø, and å characters exist in the database, and that they're rendered correctly in the frontend, and also in the backend if I refresh the entire page), but the form that is refreshed and rerended inside the tree leaf and which now contains the edited and saved data, now shows special characters like "?" for text fields, and for text areas it's the same character except it displays like a diamond with a question mark inside of it - this is also how it looks if I do a View Source on the page.

If I choose to change something else inside the form and save again, all the "?" characters are now stripped away effectively killing all æ, ø, and å characters.

Has anyone experienced something similar or have any good ideas about where I might go and look to find clues?

Below are the headers from my request as shown by Firebug.

Thanks in advance for any help, Daniel :slight_smile:

Headers:

FYI, I have another administration module which does not use the tree structure, but still uses a remote_form_for just like the other administration module, however this one has no problems like described above. Its headers on a save are here:

Ok, I just spotted the difference in content-type on the different headers, text/html vs. text/javascript. The latter breaks. Still stumped, though. Any ideas?

More info:

The one that breaks uses render :update, while the 'nice' one uses render :partial...

Not sure if that means that the first one is RJS, and the other is not, but either way... I'm a bit 'fused about what to do about this... I can't very well alter the content-type to text/html as it really IS javascript and needs to be executed, not inserted...

Argh!

Apologies, it had nothing to do with AJAX, it was the fact that I was converting from UTF-8 to ISO-8859-1 before_validation because the backend server is MS SQL, and forgetting to convert back after save. I've done that now, and life is sweet :slight_smile: