Ajax € (euro) character problem

902 views
Skip to first unread message

Martones

unread,
Sep 10, 2012, 9:52:44 AM9/10/12
to google-we...@googlegroups.com
Hey guys, I'm aware my problem is likely not GWT related but hopefuly you can point me in the right direction. All X-requests I'm making work fine (French application with plenty of accents), except for the euro (€) character. 

Here are some facts : 
  • I'm getting "?" or other unknown chars at the server side if I try to send €
  • GWT 2.4/2.5RC1 + PHP 5 on IIS7
  • I think I got everything UTF-8 shaped :
    • eclipse output, host page charset, POST php page (using Notepad++ and converting to UTF8-without BOM), utf8 meta in the PHP page, my database fields (even though my tests fail even if I dont insert the data into a file and just log them somewhere or str_cmp('€') them)
  • I'm using RequestBuilder and sending my data with somthing like this : 
    • builder.setHeader("Content-Type", "application/x-www-form-urlencoded")
    • builder.sendRequest(URL.encodeQueryString(jsonRequest.toString()),callback) where jsonRequest is my JSONObject that contains all the server needs for the request processing
  • server side I urldecode and utf8_decode (not sure if the last one is usefull)
There I think its all the essential I can think of. I think I'm messing with some big fact that I'm not aware of, I admit that I dont know enough about encoding and headers.

Many thanks for any clue (even if you slap me in a constructive maner !)

Abraham Lin

unread,
Sep 10, 2012, 9:58:13 AM9/10/12
to google-we...@googlegroups.com
You'll need to set the encoding as part of the "Content-Type" header:

builder.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

The default encoding is ISO-8859-1, which does not support the euro symbol (I believe the standard was established prior to the formation of the EU).

-Abraham

Thomas Broyer

unread,
Sep 10, 2012, 10:10:10 AM9/10/12
to google-we...@googlegroups.com
First, check the request payload: is the € sent as either "%E2%82%AC" or "\u20AC"?
If that's the case, then your problem is purely server-side, and you'd have better luck in a PHP forum.

Martones

unread,
Sep 10, 2012, 10:18:19 AM9/10/12
to google-we...@googlegroups.com
Thanks alot for your quick answer guys. I've changed my header as you advised Abraham, it doesnt seem to fix it. 
Thomas, my payload is %E2%82%AC.

Abraham Lin

unread,
Sep 10, 2012, 10:32:35 AM9/10/12
to google-we...@googlegroups.com
I just re-read your original post, and I think the problem is that you're using utf8_decode on the server side. According to the documentation, utf8_decode converts a UTF-8 string into ISO-8859-1, which doesn't support the euro symbol. Have you tried removing that call? (You should probably specify the encoding on the client side anyway, as that's really the only way to authoritatively communicate the encoding to the server).

-Abraham

Ludovit Martonyik

unread,
Sep 10, 2012, 10:47:50 AM9/10/12
to google-we...@googlegroups.com
Actualy I tested many combinations of utf8_decode, utf8_encode and urldecode. But yes now I think that the € arrives well in my log file. Many thanks for all your advice. I think that now my search continues on the PHP/DB side as Thomas said :)



2012/9/10 Abraham Lin <atomknig...@gmail.com>
I just re-read your original post, and I think the problem is that you're using utf8_decode on the server side. According to the documentation, utf8_decode converts a UTF-8 string into ISO-8859-1, which doesn't support the euro symbol. Have you tried removing that call? (You should probably specify the encoding on the client side anyway, as that's really the only way to authoritatively communicate the encoding to the server).

-Abraham

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/OZ4B5Zb9RQoJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages