You can use encodeURIComponent to encode in the foreground, and C # to use SERVER.URLDECODE (paras) decoding to resolve this issue
Front desk JS:
$.ajax ({ URL: "", Type: "POST", data: {"Paras": encodeURIComponent (Json.stringify (paras))}, Success:function (data) { }});
C # Backstage:
String str= Server.urldecode (paras);
This will ensure that the parameter is not truncated by #.
Above.
--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------
Also attached are several methods of JS encoding decoding (refer to w3school:http://www.w3school.com.cn/jsref/jsref_obj_global.asp):
encoding function escape encodeURI encodeuricomponent corresponding decoding function unescape decodeURI decodeuricomponent
Escape ():
Encodes the specified string, in addition to 0-255, with the Unicode character set. All space characters, punctuation marks, special characters, and more associated non-ASCII characters will be converted to the character encoding in the%xx format (XX equals the encoded 16-digit number of the character in the character set table) such as: the encoding of the whitespace corresponds to%20.
The method does not encode ASCII letters and numbers (0-9,A-Z,A-Z), nor does it encode the following ASCII punctuation marks: * @-_ +. / 。 All other characters will be replaced by escape sequences.
That is, escape does not encode 69 characters: *,+,-,.,/,@,_,0-9,a-z,a-z
In order to prevent Chinese garbled, JS transfer value to Transcode, when JS with Escape () transcoding,. Net background can be decoded with Httputility.urldecode (). For example: document.cookie = "city=" +escape ($ (this). html ()); String city = Httputility.urldecode (httpcontext.current.request.cookies["City"). Value);
encodeURI ():
Encodes a string as a URI in the UTF-8 encoding format. The method does not encode ASCII letters and numbers (0-9,A-Z,A-Z) and does not encode these ASCII punctuation marks:-_. ! ~ * ' ()
The purpose of this method is to fully encode the URI, so the encodeURI () function is not escaped for the following ASCII punctuation mark with a special meaning in the URI:;/?:@&=+$,#
That is to say, encodeURI does not encode 82 characters:!,#,$,&, ', (,), *,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,a-z
Tip: If the URI component contains delimiters, such as? and #, each component should be encoded using the encodeURIComponent () method.
js function: encodeURI ("url") // encode decodeURI ("url")// decode the function of asp: Server.URLEncode ("url")// code server.urldecode ("URL ")// decode
encodeURIComponent ():
Encodes a string as a URI component in the UTF-8 encoding format.
The method does not encode ASCII letters and numbers (0-9,A-Z,A-Z) and does not encode these ASCII punctuation marks:-_. ! ~ * ' ()
Other characters (such as:;/?:@&=+$,# These punctuation marks used to separate the URI component) are replaced by one or more hexadecimal escape sequences.
That is to say, encodeURIComponent does not encode 71 characters:!, ', (,), *,-,.,_,~,0-9,a-z,a-z
Tip: Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of a URI (such as a protocol, hostname, path, or query string). Therefore, the encodeURIComponent () function escapes punctuation marks that are used to separate the various portions of the URI.
JS code:var result=encodeuricomponent (unit), asp: Server.urldecode (request[" Result"]);
Note: encodeURI and encodeURIComponent will encode the string into the UTF-8 format.
Summarize:
1 using encodeuricomponent when passing parameters
2 when you make a URL jump, you can use encodeURI as a whole
3 JS use escape when using data
The encoding, decoding type and description in JS