There are some special characters in the URL transmission parameters, and these symbols cannot be passed directly in the URL. If you want to pass these special symbols in the URL, then their encoding must be used.
The following table lists some URL special symbols and encoded hexadecimal values.
1. + The + sign in the URL represents a space%2B
2. Spaces in the URL can be marked with a + sign or encoded with %20
3. / separates directories and subdirectories%2F
4. ? Separate the actual URL and parameters %3F
5. % specifies the special character %25
6. # means bookmark%23
7. & Separator %26 between parameters specified in the URL
8. = The value of the parameter specified in the URL%3D
Solution:
The replace() method will only replace the first matching character if str.replace("-","!") is used directly.
And str.replace(//-/g, "!") can replace all matching characters (g is a global flag).
replace()
Replace character variables in js as follows:
data2=data2.replace(//%/g,"%25");
data2=data2.replace(//#/g,"%23");
data2=data2.replace(//&/g,"%26");