Hey all, Anyone got some quick advice on international character submission via Prototype''s Form.Serialize? The base scenario: I set the charset on my page to ISO-8859-1, which seems to be what everyone uses. If I submit a regular form with a standard webpage, I get international characters (like an accented "e", or and AE legature) encoded as 1-byte ascii code values. The problem scenario: When I submit the same thing with Prototype over XMLHttpReq with the parameter set to a Form.Serialize of some form, I get that same character encoded in what looks like its 2-byte Unicode representation. The real question: Basically it boils down to the built-in encodeUrlComponent returning 2-byte encodings, while the browser seems to do a 1-byte encoding. My server isn''t handling the 2-byte encoding correctly. It seems weird to me that the two methods would produce differing results. Am I doing something wrong? Thanks again for any tips! Rahul _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I have the same problem. I''m not entirely sure how to fix it, but I will probably be working on it this weekend. If I figure it out, I''ll let you know. One thought that occurs to me, that I haven''t tried, but it might work. Can you put a charset in the <script> tags? Like: <script type="text/javascript; charset=ISO-8859-1"> (or some other method perhaps?). That might set Javascript into the correct encoding. Just a thought, if you have some time to research and try it out, let me know how it goes. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Rahul Bhargava Sent: Friday, April 14, 2006 7:23 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] character encoding in ajax submit Hey all, Anyone got some quick advice on international character submission via Prototype''s Form.Serialize? The base scenario: I set the charset on my page to ISO-8859-1, which seems to be what everyone uses. If I submit a regular form with a standard webpage, I get international characters (like an accented "e", or and AE legature) encoded as 1-byte ascii code values. The problem scenario: When I submit the same thing with Prototype over XMLHttpReq with the parameter set to a Form.Serialize of some form, I get that same character encoded in what looks like its 2-byte Unicode representation. The real question: Basically it boils down to the built-in encodeUrlComponent returning 2-byte encodings, while the browser seems to do a 1-byte encoding. My server isn''t handling the 2-byte encoding correctly. It seems weird to me that the two methods would produce differing results. Am I doing something wrong? Thanks again for any tips! Rahul _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Hi Rahul, Prototype uses UTF-8 encoding only. I would change your page charset to UTF-8 from ISO-8859, this will definitively the best solution and once for ever (UTF-8, that is Unicode covers all characters on our planet!) Best regards JAnko Rahul Bhargava wrote:> Hey all, > > > > Anyone got some quick advice on international character submission via > Prototype’s Form.Serialize? > > > > The base scenario: > > I set the charset on my page to ISO-8859-1, which seems to be what everyone uses. If I submit a regular form with a standard webpage, I get international characters (like an accented “e”, or and AE legature) encoded as 1-byte ascii code values. > > > > The problem scenario: > > When I submit the same thing with Prototype over XMLHttpReq with the > parameter set to a Form.Serialize of some form, I get that same > character encoded in what looks like its 2-byte Unicode representation. > > > > The real question: > > Basically it boils down to the built-in encodeUrlComponent returning > 2-byte encodings, while the browser seems to do a 1-byte encoding. My > server isn’t handling the 2-byte encoding correctly. It seems weird to > me that the two methods would produce differing results. Am I doing > something wrong? > > > > Thanks again for any tips! > > > > Rahul >
> Prototype uses UTF-8 encoding only. I would change your page charsetto> UTF-8 from ISO-8859, this will definitively the best solution and once > for ever (UTF-8, that is Unicode covers all characters on our planet!)It''s not an option for me at this point. Your server code needs to be set up to use UTF-8 for everything to work correctly. My database and server code is all ISO-8859-1, and changing it is not trivial (although that is the ultimate goal). I''ve not seen anything in Prototype that specifically makes it UTF-8 only. I believe javascript has the ability to use various encodings. Greg
Gregory, UTF-8 encoding only is stated in Scriptaculous docs about in-place editor: http://wiki.script.aculo.us/scriptaculous/revision/Ajax.InPlaceEditor?rev=16 "Character encoding The form data is sent encoded in UTF-8 regardless of the page encoding. This is as of the prototype function Form.serialize. " Best regards Janko Gregory Hill wrote:>>Prototype uses UTF-8 encoding only. I would change your page charset > > to > >>UTF-8 from ISO-8859, this will definitively the best solution and once >>for ever (UTF-8, that is Unicode covers all characters on our planet!) > > > It''s not an option for me at this point. Your server code needs to be > set up to use UTF-8 for everything to work correctly. My database and > server code is all ISO-8859-1, and changing it is not trivial (although > that is the ultimate goal). I''ve not seen anything in Prototype that > specifically makes it UTF-8 only. I believe javascript has the ability > to use various encodings. > > Greg > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Janko Mivšek Svetovalec za informatiko EraNova d.o.o. Ljubljana, Slovenija www.eranova.si tel: 01 514 22 55 faks: 01 514 22 56 gsm: 031 674 565
A bit more about that from: http://dev.rubyonrails.org/ticket/2151: Ajax.InPlaceEditor calls Form.serialize() from Prototype internally to serialize the dynamically created form. This function uses the JavaScript? function encodeURIComponent() to encode URI components, which works by encoding the provided string (in this case the value of the text field) with UTF-8 escape sequences. Because JavaScript? provides no way to encode to arbitrary encodings, using UTF-8 (which is the de facto standard for multi-language pages) is the only "easy" way to go here. If you have to use ISO-8859-1, you can manually change prototype.js to use escape() instead of encodeURIComponent(). See http://xkr.us/articles/javascript/encode-compare/ for some additional information. Janko Mivšek wrote:> Gregory, UTF-8 encoding only is stated in Scriptaculous docs about > in-place editor: > > http://wiki.script.aculo.us/scriptaculous/revision/Ajax.InPlaceEditor?rev=16 > > > "Character encoding > > The form data is sent encoded in UTF-8 regardless of the page encoding. > This is as of the prototype function Form.serialize. " > > Best regards > Janko > > Gregory Hill wrote: > >>> Prototype uses UTF-8 encoding only. I would change your page charset >> >> >> to >> >>> UTF-8 from ISO-8859, this will definitively the best solution and once >>> for ever (UTF-8, that is Unicode covers all characters on our planet!) >> >> >> >> It''s not an option for me at this point. Your server code needs to be >> set up to use UTF-8 for everything to work correctly. My database and >> server code is all ISO-8859-1, and changing it is not trivial (although >> that is the ultimate goal). I''ve not seen anything in Prototype that >> specifically makes it UTF-8 only. I believe javascript has the ability >> to use various encodings. >> >> Greg >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >-- Janko Mivšek Svetovalec za informatiko EraNova d.o.o. Ljubljana, Slovenija www.eranova.si tel: 01 514 22 55 faks: 01 514 22 56 gsm: 031 674 565
Maybe Matching Threads
- In place editing and external control
- Delayed input posting
- Tabulation with ENTER key
- Bug or feature: using "ANY" as a generic field class (was: '[R] Is there a (virtual) class that all R objects inherit from?)
- Problems building own package (Error: "package has been build before R-2.10.0")