NYCPHP Meetup

NYPHP.org

[nycphp-talk] AJAX and character encoding

Marc Antony Vose suzerain at suzerain.com
Mon May 8 20:14:45 EDT 2006


At 10:24 AM -0400 5/8/06, Adam Maccabee Trachtenberg wrote:
>On Mon, 8 May 2006, tedd wrote:
>
>>  Correct me if I'm wrong, but if you are simply injecting code into a
>>  static web page, isn't it the <meta... utf-8> tab of the page that
>>  sets the charset?
>>
>>  Ajax simply prompts a php routine to prepare stuff for ajax to take
>>  back an inject into whatever you want between html tags, right? At
>>  least that's the way I'm doing it -- but, I'm simple that way.
>
>Without doing any research, I would also guess the setting the charset
>via a meta or HTTP header should fix this.
>
>If not, does you server have the iconv() extension enabled? That lets
>you convert between arbitrary character sets.
>


To clarify this for everyone: the character encoding of the page is 
in windows-1252.  Therefore, in my opinion, the browser ought to 
display all the content in the character set.

But, in researching AJAX, I've found that the httprequest object 
defaults all communication to UTF-8, no matter whether you set 
character encoding on it with a PHP header or not.  Most browsers 
seem to detect this and display the proper characters.

IE, though, doesn't.  I assume it would display the characters fine 
if my entire page was set with UTF-8 encoding, but unfortunately, 
unless I get my client to change their system, this isn't going to 
happen.

Here's the page in question (a rare book seller with a flair for the 
whimsical):

http://209.160.72.79/btc/search_results?btc_keywords=grass&x=0&y=0

There is a 'module' at the top of the page with some author info. 
Int he middle, on the left, are some product results.  Then, on the 
right, a narrower module contains related reference information about 
the author...this is the info coming into the page from AJAX (in this 
case, there are only a few responses, but sometimes there are dozens, 
in which case that module has some navigation to further items).

So, Gunter Grass' name gets mangled in IE.  It looks fine in all 
browsers that matter on OS X, and with another 'fix' I can get it to 
work in Firefox on Windows...but IE is just not doing it.

If anyone has any ideas, feel free to enlighten me.

I am trying to lobby them to perform some character encoding on the 
data before it gets to the server (it's a complicated system where 
all data is managed in an offline database, and it synchronizes with 
the web server via a series of cron jobs on their end and on the 
server).

Cheers,

Marc



More information about the talk mailing list