Home  >  Article  >  Web Front-end  >  JS and C# encoding and decoding_javascript skills

JS and C# encoding and decoding_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:11:051101browse

There are 69 characters that are not encoded by escape: *, ,-,.,/,@,_,0-9,a-z,A-Z

encodeURI has 82 non-encoded characters: !, #, $, &, ', (,), *, ,,, -,.,/,:,;,=,?,@,_,~, 0-9, a-z, A-Z

encodeURIComponent has 71 unencoded characters: !, ', (,), *, -, ., _, ~, 0-9, a-z, A-Z

1.

JS: escape :

You can use escape when using data in js
For example: history record in collection.
When encoding unicode values ​​other than 0-255, the %u**** format is output. In other cases, the encoding results of escape, encodeURI, and encodeURIComponent are the same.

Decode using: unescape

C#:

HttpUtility.UrlEncode
HttpUtility.UrlDecode

2.

JS: encodeURI:

You can use encodeURI as a whole when performing url jump
For example: Location.href=encodeURI("http://cang.baidu.com/do/s?word=Baidu&ct=21");

Decode using decodeURI();

C#: decodeURIComponent

3.

JS: encodeURIComponent:

You need to use encodeURIComponent when passing parameters, so that the combined url will not be truncated by special characters such as #.

For example:

Decode using decodeURIComponent()

C#:

[HttpContext.Current.]Server.UrlDecode

[HttpContext.Current.]Server.UrlEncode

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn