URL encoding to enocode spaces with plus
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?
你自己做替换是非常简单的:
var encoded = escape(s).replace(/%20/g, "+");
alert(encoded); // outputs "this+is+test+%3A)"
链接地址: http://www.djcxy.com/p/26524.html
上一篇: 替换为JavaScript转义?
下一篇: 使用加号来编码空格的URL编码