ilyatom ilyatom - 3 months ago 17
Ajax Question

JSON.stringify replace pluses with spaces

I use AJAX and send string someString to php-handler

xmlHttp.open("POST", url, true);
var someString = 'Foo+Bar';
var params = 'operation='+operation+'&json='+JSON.stringify(someString);
xmlHttp.send(params);


If someString contains '+' it replacing with space. As I could read, it is normal work of JSON.stringify, but how can I get pluses (using JS only)?

The second question is what other symbols replacing by JSON.stringify?

Answer

That has nothing to do with JSON.stringify.

The conversion of + to a is done by the URL parser on the server. A + is one of the ways you can represent a space in a URL (the other being %20).

To convert text to make it safe to insert into a URL, use encodeURIComponent.