The right encoding for your Ajax views

Yesterday, I wrote about my troubles with UTF-8. A very similar problem I had today: the content I requested by Ajax had the wrong encoding. I found the solution relatively fast: I have to set the content type in my Ajax layout. Here is my modified Ajax layout:

header(‘Content-type: text/html;charset=UTF-8’);
echo $content_for_layout;


  1. Posted January 17, 2006 at 3:58 pm | Permalink

    I am on rev 1806 and I don’t have this problem with my AJAX. I simply request with the ‘/bare’ in front of all my requestactions and AJAX.Updaters and haven’t had a problem yet. Can you go into more detail about the problem this was causing?

    The only problem I have is that I don’t think drag and drop works if you ajax stuff that the div is inside a table cell. And the AJAX code to make that div draggable is inside another div that is called via AJAX. If I refresh the entire page it is fine, but if I use AJAX to refresh the one div and that one has script to activate the other, broken in IE.

  2. Posted January 17, 2006 at 4:50 pm | Permalink

    Well, I use rev 1818 of CakePHP, and UTF-8 as encoding for my tables (I create them with CHARSET=utf8) as well as for my html code. The problem was now that German special characters like ä ö ü were not displayed correctly when I got them from the server via Ajax request. Here my code I use to do the Ajax request:

    $ajax->form(‘searchform’, array(‘url’ => ‘/users/ajaxSearch’, ‘update’ => ‘results’))

    I cannot say anything about drag and drop since I do not have used it yet. If you experience problems, ask in the IRC channel and/or write a bug report.

  3. Posted January 17, 2006 at 5:42 pm | Permalink

    Hm if you are going to write a bug report make sure it’s going to the right vendor. Because AFAIK cake uses Prototype/Scriptacoulus for AJAX which is not modified by the Cake Authors in any way.

%d bloggers like this: