I’m currently sending an ajax request to a servlet and losing some information along the way. The parameter I am concerned about(losing data from) is the “comment” parameter. Below you can see my last 4 lines of ajax.
var params = "name=" + name + "&email=" + email + "&comment=" + comment + "&player_id=" + player_id;
xmlhttp.open("POST", 'comment', true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send(params);
When I alert my params before the send and after the declaration they look like this:
name=Chris&email=email@gmail.com&comment=Hey, check this song out on groovershark http://grooveshark.com/#!/s/Here+feat+Soulive/2YDJIw?src=5&player_id=4
However in my servlet if I do a print line for the comment parameter right after getting it I get this output:
Hey, check this song out on groovershark http://grooveshark.com/#!/s/Here feat Soulive/2YDJIw?src=5
The problem is the "+" marks disappear somewhere along the request from ajax to the container and I have no idea why. I have narrowed it down to this problem area finally b/c I actually did not notice this until all the way in the database connection with the help of another stack overflow member. So if anyone could let me know what I can do to get my "+" characters back I would really really appreciate! Thank you so much!
You should encode your params prior to send them, like this: