views:

81

answers:

6

I cant figure out why in ajax post "+" sign converts to " ".please explain ?

+2  A: 

"+" is the url encoded symbol for space. As such, when your post data is decoded the "+" is converted to a space.

g .
+1 for winning the race and answering first.
Langdon
+2  A: 

Chances are that you are using the + sign in an URL, where it is rightly converted into a space, as + is the URLEncoded representation of a space character.

Run escape() on whatever value you are putting into your URL to get it into URL-encoded form.

Pekka
+4  A: 

It's how URL encoding works. If you want a plus sign it's %2B, but you should really just escape or encode the data you're sending to the server. Type "a+b c" in here.

Langdon
+1  A: 

That's just standard url encoding. Plus signs are converted to spaces on the server. If you want to pass a plus sign you need to escape it as %2b.

tvanfosson
+2  A: 

This is because URL Encoding converts spaces to + since spaces aren't valid in URLs.

Normally characters are converted to % followed by two hex digits, but having + instead of %20 makes URLs more readable.

If you encode your + as %2B that should work.

Dave Webb
+2  A: 

Use the encodeURIComponent() function to turn your data in valid encoded data for the request:

xhr.open("POST", url, true);
xhr.send(encodeURIComponent(postdata));
Roland Bouman
Thanks , i am searching for a right function to convert.
Kumar