Prototype Encoding Issue
Another encoding issue for AJAX libraries after fixing something similar last year with AjaxAC and middle eastern encoding, yesterday I noticed that prototype have similar issue. The problem with prototype is the usage UTF-8 as default encoding even if your page have a different encoding, this will make the data exchanged between client and server incorrect, and in our cases the SQL executed in server side return no results.
I grabbed today the latest prototype 1.5.0_rc1 included with script.aculo.us, but be sure to get the latest one from their website because the script have changed and version remain the same. In the latest version you can notice a new parameters which have been added to the options "encoding" :
In this case be sure to set the appropriate encoding that your page is using for example windows-1252, windows-1256 ... etc. It should solve the problem if ... encodeURIComponent() wasn' t used for escaping special characters.
And that's the second issue for Prototype which is the usage of encodeURIComponent() which replace each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character. The problem here that all escaping functions replace non-ASCII characters with Unicode ones, and in this case even if you set the unicode by default to windows-1252 for example, a special character will be replaced by its equivalent in unicode.
The solutionThere is two possible solutions, first find a replacement for the escaping method, and the second solution which is more easy to implement is using PHP iconv extension :
So even if Prototype send data in Unicode you can get it again in its original encoding and continue your process. Will face this bug anybody who work with middle eastern or asian encoding, even french, german, dutch and any encoding which using non-ASCII character. If you use already UTF-8 in your application and database, you should be safe, and won't face this issue. Let me know if someone have found similar issue for other AJAX libraries.











AJAX Magazine's RSS
