leon_nerd Posted December 16, 2009 Share Posted December 16, 2009 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. Am I doing something wrong? How can I read POST variables that contains "+" character. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/185394-post-variables-contains/ Share on other sites More sharing options...
cags Posted December 16, 2009 Share Posted December 16, 2009 How is it getting put in the $_POST variable? The + symbol is one of the standard methods for encoding a space, which is obviously what is happening, I think using urlencode should solve the problem. Link to comment https://forums.phpfreaks.com/topic/185394-post-variables-contains/#findComment-978727 Share on other sites More sharing options...
leon_nerd Posted December 16, 2009 Author Share Posted December 16, 2009 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? Link to comment https://forums.phpfreaks.com/topic/185394-post-variables-contains/#findComment-978732 Share on other sites More sharing options...
cags Posted December 16, 2009 Share Posted December 16, 2009 If the string is built using JavaScript you can't, use %2B instead of the + as that is the encrypted value. If needs be you can then use urldecode in the script your calling with AJAX. Link to comment https://forums.phpfreaks.com/topic/185394-post-variables-contains/#findComment-978733 Share on other sites More sharing options...
salathe Posted December 16, 2009 Share Posted December 16, 2009 So, how can I use the urlencode() here since I am creating the parameter string in javascript? Use the JavaScript encodeURIComponent function. Link to comment https://forums.phpfreaks.com/topic/185394-post-variables-contains/#findComment-978737 Share on other sites More sharing options...
leon_nerd Posted December 16, 2009 Author Share Posted December 16, 2009 Thanks a lot salathe . That worked. It was kind of silly of me to forget this simple function. Thanks everyone for putting in your views. I was not expecting this kind of turnaround time for my problem. Just amazing to see this kind of response. Will be around. Thanks Link to comment https://forums.phpfreaks.com/topic/185394-post-variables-contains/#findComment-978759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.