Plus sign not shown

S

souporpower

Hi All

I am using ajax as follows:

var parameters = "groups=" + escape([email protected]);
var url="/mydomain/ajaxCall";

if (req != null) {

req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
req.send(parameters);
req.onreadystatechange=processResp2;
}

I noticed that inside the ajaxCall the plus (+) sign is replaced with
a space in the string escaped (myemail (e-mail address removed))

Could someone tell me how to do this correctly?

Thanks
 
B

Bart Van der Donck

I am using ajax as follows:

var parameters = "groups=" + escape([email protected]);
var url="/mydomain/ajaxCall";

        if (req != null) {

              req.open("POST", url, true);
              req.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
              req.send(parameters);
              req.onreadystatechange=processResp2;
        }

I noticed that inside the ajaxCall the plus (+) sign is replaced with
a space in the string escaped (myemail (e-mail address removed))

Could someone tell me how to do this correctly?

'+' is a reserved character; it is one of the 2 possible ways to
percent-encode a space (the other one is '%20'). You should send '%2B'
if you want to send the plus-sign.

See section 2.2.in RFC 3986:
http://www.ietf.org/rfc/rfc3986.txt

In your code:

parameters = parameters.replace(/\+/g,'%2B');

More info:
http://en.wikipedia.org/wiki/Percent-encoding

Hope this helps,
 
S

souporpower

'+' is a reserved character; it is one of the 2 possible ways to
percent-encode a space (the other one is '%20'). You should send '%2B'
if you want to send the plus-sign.

See section 2.2.in RFC 3986:http://www.ietf.org/rfc/rfc3986.txt

In your code:

  parameters = parameters.replace(/\+/g,'%2B');

More info:http://en.wikipedia.org/wiki/Percent-encoding

Hope this helps,

Thanks for the clarification. I tried replace as suggested above
and also encodeURI. The plus sign still gets dropped.

I don't know what else to try. Your kind help is appreciated.
 
T

Thomas 'PointedEars' Lahn

Bart said:
I am using ajax as follows:
var parameters = "groups=" + escape([email protected]);
var url="/mydomain/ajaxCall";
if (req != null) {
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
req.send(parameters);
req.onreadystatechange=processResp2;
}
I noticed that inside the ajaxCall the plus (+) sign is replaced with
a space in the string escaped (myemail (e-mail address removed))
Could someone tell me how to do this correctly?
'+' is a reserved character; [...]
In your code:

parameters = parameters.replace(/\+/g,'%2B');
[...]

I tried replace as suggested above and also encodeURI. The plus sign
still gets dropped.

I don't know what else to try. Your kind help is appreciated.

You could post the code that you are using. The code that you have posted
so far does not run because it is syntactically invalid (you did not quote
the argument of escape); who knows what other typos/omissions are there.

Please trim your quotes to the relevant parts.


PointedEars
 
S

sasuke

Thanks for the clarification. I tried replace as suggested above
and also encodeURI. The plus sign still gets dropped.

I don't know what else to try. Your kind help is appreciated.

Use encodeURIComponent() instead of escape() for encoding your POST
data.

/sasuke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top