Page 1 of 1

POST Variables contains "+"

Posted: Wed Dec 16, 2009 3:01 pm
by leon_nerd
Hi Guys,

I am making some AJAX calls and passing some POST variables. The POST parameters happen to contain "+" character. It is something like prod1=A4+&prod2=fullsize. When I try to read the $_POST[prod1] it returns "A4 ". There is no + sign and it replaced by a white space instead. Am I doing something wrong? How can I read POST variables that contains "+" character.

Thanks in advance.

Re: POST Variables contains "+"

Posted: Wed Dec 16, 2009 3:19 pm
by AbraCadaver
urlencode()

Re: POST Variables contains "+"

Posted: Wed Dec 16, 2009 3:29 pm
by leon_nerd
I am making an AJAX call. So, I am building up the string using the javascript "+" to concatenate various variables for POST. Then I am using
http_request.open('POST', url, true);
. So, how can I use the urlencode() here since I am creating the parameter string in javascript?

Re: POST Variables contains "+"

Posted: Wed Dec 16, 2009 3:34 pm
by AbraCadaver
leon_nerd wrote:I am making an AJAX call. So, I am building up the string using the javascript "+" to concatenate various variables for POST. Then I am using
http_request.open('POST', url, true);
. So, how can I use the urlencode() here since I am creating the parameter string in javascript?
I think it's this in js:

Code: Select all

url = escape(url);

Re: POST Variables contains "+"

Posted: Wed Dec 16, 2009 3:36 pm
by AbraCadaver
Actually, you may only want to escape() the actual values and not the full url.

Re: POST Variables contains "+"

Posted: Wed Dec 16, 2009 4:14 pm
by leon_nerd
Ahh...I got it working. So silly of me. Just a simple encodeURIComponent() did the trick. Thanks a lot guys for your inputs. I really appreciate your time :)