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. URL medium means space +
2. Space spaces in URL can be represented by numbers or encoding
3. / Separates directories and subdirectories/
4. ? Separates actual URLs and parameters?
5. % specifies special characters %
6. # represents bookmarks #
7. & in URL The delimiter between specified parameters &
8. = The value of the specified parameter in the URL =
Solution:
replace() method If you directly use str.replace("-","!"), it will only replace the first matching character .
And str.replace(/-/g,"!") can replace all matching characters (g is a global flag).
replace()
The replacement character variables in js are as follows:
data2=data2.replace(/%/g,"%");
data2=data2.replace(/#/g," #");
data2=data2.replace(/&/g,"&");