Safari and Ajax with UTF-8 Encoding
Date : 2008 02 14 Category : Design & UsabilityCombining foreign characters, JavaScript and calls to the server in a JSON format sounds like trouble — and it is. But this time Safari is causing the problems instead of IE. If encoding is not specified in the headers, characters like Å, Ä and Ö will not display properly. Now, if you have come across this problem, I’m sure you have seen the solution presented by macdiggs, which seems to have fixed the problem by adding the proper encoding in the header.
header("Content-type:text/html; charset=utf-8");Because the programming gods don’t like me, this didn’t do the trick for me. Looking over my code, all encoding is properly set. The HTML is:
header("Content-Type: text/html; charset: utf-8");And the CSS:
header("Content-Type: text/css; charset: utf-8");And so on with all other file types. The permanent solution for me was to set this in the .htaccess file.
AddDefaultCharset UTF-8I suspect that somewhere in the application the encoding is being transferred incorrectly, but all tools I can use (Firebug, page load info) say otherwise. Even changing the default charset in Safari preferences didn’t fix the problem. If you’re running into something similar, know that the issue is with encoding. If fixing it on a page level doesn’t work then the .htaccess change may be what you need.
