I am using $.Ajax to call a web method and passing few parameters which are received in webmethod and used for server request. However, one of the param value may have special charaters including +. I could do away with all others by using encoding but seems + is not getting encoded. Encoded value for space ' ' is + so may be it is considered already encoded and skiped. Moreover, while decoding, that + is considered as space and shown as space in final text value. I need to persist +. How can I do it?
Asked
Active
Viewed 79 times
1
-
How are you encoding it? – deceze May 09 '13 at 09:13
-
Using javascript function encodeURIComponent() – guravman May 09 '13 at 09:14
-
encodeURIComponent(' ') is %20 while encodeURIComponent('+') should be %2B. Using encodeURIComponent() should be fine. I think your problem is from other place. – Brian May 09 '13 at 09:50
-
The problem was myParam can contain a text value as "This is sample text containing + character". From this, + was not getting encoded. Thanks Brian! Your comment and link http://stackoverflow.com/questions/13574980/jquery-replace-all-instances-of-a-character-in-a-string shown me the path. Now I am doing encodeURIComponent(myParam.replace(/\+/g, '\%2B')) and it is working fine! – guravman May 09 '13 at 10:05