Was experimenting with some basic http post stuff with php and ran into this problem.
1.php:
<head>
<script src="/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>
2.php:
<?php
echo $_POST['param'];
?>
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 'text/plain'
instead of the default 'application/x-www-form-urlencoded'
. In this case, $_POST['param']
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 ( '+' ) ?