[Greasemonkey] Javascript character encoding problem

Jonas Lundberg my.name.is.hans at gmail.com
Wed Apr 5 13:39:58 EDT 2006


Thank you. The encodeURI suggestion would work, which I am quite happy
about. However, then I would have to un-encode it on the server side
as well, which adds processing and a source for errors. The encoding
headers seems to be identical in my two cases. It thus looks like that
it is Javascript that serializes strings with international characters
incorrectly. Adding to the confusion, it seems that the string is
correctly serialized if I use the alert(); function, but not in the
GM_xmlhttpRequest function.

Therefore, I was hoping that there would be a way to set Javascript to
work with international characters. Is there really no such way? That
is extremely surprising.... in a bad way...

Regards
Hans

On 4/5/06, Anton Berezin <tobez at tobez.org> wrote:
> On Wed, Apr 05, 2006 at 12:23:30AM +0200, Jonas Lundberg wrote:
> > Although this must be a common question, I have not found a good answer to it.
> >
> > I am posting a form through GM_xmlhttpRequest:
> >
> > GM_xmlhttpRequest({
> >     headers: {
> >         'Content-type': 'multipart/form-data; boundary=shapecms',
> >     },
> >     data: data,
> >
> > However, Swedish characters in the "data" variable, are scrambled.
>
> > -----------------------------41184676334
> > Content-Disposition: form-data; name="titel"
> >
> > ~AP~AP
> > -----------------------------41184676334
>
> I had success with UTF-8 in GM_xmlhttpRequest(), but I was using
>
>    'Content-type': 'application/x-www-form-urlencoded'
>
> - with the POST request - and was doing encodeURIComponent() for stuff
> inside the data.  Then again, the backend expected data to be in UTF-8.
>
> Failing that, you might want to experiment with different values of
> the Transfer-Encoding header.
>
> \Anton.
> --
> An undefined problem has an infinite number of solutions.
> -- Robert A. Humphrey
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list