0

I have an application that needs to sign form data before it is sent to server. In the signing method, I have to escape all form input values with javascript, sign them and then send the signed data to server for cross matching. The remote server is escaping form data in a way that it enocodes all spaces with plus.

So if my form data is:

this is test :)

The encoded output should be

this+is+test+%3A)

But I tested javascripts encodeURIComponent, encodeURI and escape. All of them gives me the following output:

this%20is%20test%20%3A)

Any ideas which function is right for this?

Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
Enn Fenn
  • 400
  • 2
  • 5
  • 15

1 Answers1

3

It is quite straightforward to do the replacement yourself:

var encoded = escape(s).replace(/%20/g, "+");
alert(encoded); // outputs "this+is+test+%3A)"
laurent
  • 88,262
  • 77
  • 290
  • 428