PDA

View Full Version : "Unescaping" data sent by AJAX to then use w/ PHP


broncozr
06-04-2010, 04:13 PM
I'm sending data that I JavaScript "escape()" from one page to another using an AJAX XMLHttpRequest. When it gets to the other PHP page, I would like to JavaScript "unescape()" that data. On the 2nd PHP page, I'm basically writing out an XML page (using PHP), from which I get several variables to return to the first page.

My question is how do I JavaScript "unescape()" the variables on the 2nd page so that I can use them in PHP. PHP is doing all of the work on the variables on the 2nd page. So, I'm basically trying to get my hands on a JavaScript-unescaped() version of the PHP $_REQUEST variables.

Any suggestions?

Thanks.

broncozr
06-04-2010, 07:12 PM
The data that I'm sending is usually text with some funky (e.g. Microsoft quotes) characters mixed in.

e.g. sending this with an AJAX request
‘some text’ `

gives me this on the 2nd PHP page that manipulates the data and stores it (I just store the data in a .txt file as a backup):
%u2018some%20text%u2019%20%60


1. Do I even need to escape it when sending the request?
2. How can I get the escaped data back to this on the PHP page that receives the request:
‘some text’ `


I guess my questions go to the larger question of what good practice is when sending/receiving AJAX requests with respect to escaping/unescaping.....

Hope that's clearer. Thanks.