AJAX Gotchas

Alex Bosworth has compiled a list of “gotchas” that new AJAX developers seem to fall prey to on a regular basis. He has also posted the list on a wiki so that readers can contribute their own common AJAX pitfalls.

Among the list of gotchas was this gem that lends greater weight to my recent coverage of character encodings:

Ajax uses UTF-8. Normal forms are sent using the encoding of the parent page. Thus a SJIS encoded page will default to sending form content encoded in SJIS. Ajax submitted forms on the other hand will be sent as UTF-8. If for some strange reason, UTF-8 is not the character set of choice for the server, this will require a solution such as the server recognizing and translating UTF-8 responses to a desired character encoding.

For PHP developers especially, where limited out-of-the-box support for UTF-8 keeps many sites on single-byte character encodings, this issue could cause nasty surprises indeed. For example, if you want to add the ability to submit a form via AJAX and keep the standard submission method as a fallback, you could potentially end up having to support two different encodings for that submitted data!