ajax encoding pt.2: from js->escape to php->urldecode
Another brick to solve the encoding issue with ajax is settled, last week I ranted about the problem on showing data from a remote script inside a page encoded with ISO-8859-1.
This time I’ve the reverse problem, I’ve to save some data from a form to a db and then show it on another page. As usual xmlHttpRequest send data in UTF-8, so my data results always corrupted.
This time the solution is very simple, first I encode the data with javascript using the escape function then on the remote script I use the php function urldecode.
So a string like ÎÑTËRÑÅTÌÔñ�L will be escaped to %CE%D1T%CBR%D1%C5T%CC%D4%F1%C1L and then urldecoded back to ÎÑTËRÑÅTÌÔñ�L
ciuaz



[...] Sul blog in inglese nelle ultime due settimane ho scritto alcuni post, in inglese, sulle problematiche dell’utilizzo di ajax con encoding che non sono UTF-8. [...]
Which js function shall I use to decode the international text for the xmlHttprequest?
unescape
I am also facing the same problem. I tried your way like this. However, on the server side I am using Java (servlet). Funny thing is that using escape(), my servlet cannot get the parameter (it is null). However if not using escape, my servlet can get it, but crap one.
Thanks. This saved me hours of debuging.
thanks, helped a lot
to rizwan,
because in the request, the method getParamter including the decode process.
so in my way, i just use the getQueryString, and by using regular express to prase it.
hope it can help you.
Hi!
I’m a webdesigner from Brazil and I really enjoyed your posts. They were very usefull and solved my doubts.
Thank you!
Hi,
Thanks a lot for this help.
But the problem with urlencode is it is converting spaces to + and Javascript unescape is unable to convert it back to space.
Any solution?
Thanks
Hi
Aditya Mooley, use rawurlenconde function instead urlconde in your php script.
Hi!
Thanks a lot!! Searched the web for solutions, but yours is definitely the best one for me. I guess this problem will be solved in future versions of ajax, hence a simple solution is just what I wanted.
Could you give some examples of it in action?
fico.. mi mancava questo:
urldecode