[pmwiki-devel] Ajax, JSON, and character encoding

DaveG pmwiki at solidgone.com
Sun May 16 17:24:06 CDT 2010


Does anyone have any experience with character encoding and JSON returns 
to Ajax calls?

I've just spent the last week trying to work this out, and I think I've 
either complexed myself into a box, or what I'm trying to do is just wrong.

1] I'm using Ajax to make a request to the server
2] Cookbook returns a JSON object
3] I use Javascript to do things with the JSON object

This all works great. I was ready to release an Ajax enabled BlogIt unto 
the world. And then someone tested with accented characters...

JSON requires UTF-8 encoded strings. In particular PHPs json_encode 
*requires* strings to be UTF-8. So, if a wiki page is encoded with 
ISO88591 characters, and has accented characters, (ö) for example, these 
need to be converted to their UTF-8 equivalent.

Therein lies the problem. If I pass a UTF-8 encoded page back to the 
browser, I now need to make sure I decode the UTF-8 if that data is 
subsequently submitted back to the server. This seems to open a rats 
nest of encoding issues.

About the only solution I can come up with is to abandon the use of 
JSON, and simply pass back XML in my Ajax response. This is okay, but 
means re-writing everything I already did.

So, am I fundamentally missing something here, or are there other 
options I should explore?


  ~ ~ Dave




More information about the pmwiki-devel mailing list