1

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?

0

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry for stupid question... URL parser works even I use xmlHttp.open("POST", url, true), not GET?
@ilyatom — A URL is a URL, so yes. (And if you mean that you would send the data in the request body, then the default encoding that servers use to parse posted data is the same as URLs).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.