JS escape, encodeURI, encodeuricomponent encoding and decoding [turn]

Source: Internet
Author: User

Go to: http://jc-dreaming.iteye.com/blog/1702407

This paper discusses how to encode and decode the passing parameters with JS

1: The correspondence between encoding and decoding method

Escape-----------------------------------------------------unescape

encodeURI-------------------------------------------------decodeURI

encodeURIComponent-----------------------------------encodeURIComponent

2: Decoding and Encoding method usage

such as Var value1=escape (' 1² ');  var getvalue1=unescape (value1); encodeURI, Decodeuri,encodeuricomponent, encodeuricomponent usage and escape,unescape usage are all the same.

3: Differences and linkages between three coding methods

Encoding method: encodeURI, encodeuricomponent are used UTF-8 to encode the parameters, and escape is not.

Characters that will not be encoded: encodeURI: ":", "/", ";" and "?" characters are encoded.

Usage occasions: Escape does not encode URLs, if you want to encode URLs, you should use encodeURI or encodeURIComponent, the corresponding decoding method is also the case.

Recommended method Order: encodeURIComponent--encodeuri--escape.

Note: With encodeURIComponent, encodeURI in the foreground encoded string, can be directly in the background with Java decoding way Urldecoder.decode (Val, "UTF-8"); The reason is that the two methods themselves are encoded as UTF-8. It is convenient to use.

JS escape, encodeURI, encodeuricomponent encoding and decoding [turn]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.