I have the following Javascript/Mootools code:
var str = self.tI.get('value').replace(/\s/g,'+'),
data = 'action=getplaces&str=' + str + '&latLng=' + $('coords').get('value'),
r = new Request({
url: 'action.php',
method: 'get',
link: 'cancel',
onSuccess: function (response) {
/* Do Stuff */
}
}).send(data);
console.log(str);
On the first line I replace any spaces with + signs. When I log the value of str in the console, I get the appropriate value (ie: ‘blabla+bla’)
However, when I send the request, my request fails. If I look at the headers and the query string, the + sign is simply replaced again with a space (ie: ‘blabla bla’)
What’s up with that? And is there a way around it?
For anybody wondering, my problem ended up being server side. Once the data got to the server side, I was trying to incorporate it in another URL but the server had already parsed the %20 and the +’s to spaces. So had to do some string manipulation on the server side.