php encoded post param values

Jackster

New Member
Was experimenting with some basic http post stuff with php and ran into this problem.1.php:\[code\]<head> <script src="http://stackoverflow.com/scripts/jquery.js"></script></head><body> <script> function hw(){ $.ajax({ type: 'POST', url: '/2.php', data: 'param=a+b+c', success: function(d){ console.log('server said ' + d); } }); } </script> <button onclick="javascript:hw();">CLick me</button></body>\[/code\]2.php:\[code\]<?phpecho $_POST['param'];?>\[/code\]the ajax call returns with 'a b c' instead of 'a+b+c'. Why is it that '+' is encoded to a ' '(space) ?I then tried using the content type of the post request as \[code\]'text/plain'\[/code\] instead of the default \[code\]'application/x-www-form-urlencoded'\[/code\]. In this case, \[code\]$_POST['param']\[/code\] comes out to be empty ? I want to understand what exactly is going on in both these cases. What do I do on the server side to get back the original data ( '+' ) ?
 
Back
Top