The application of encode and decode in JS __js

Source: Internet
Author: User
encodeURIComponent

Encodes a text string as a valid component of a Uniform Resource Identifier (URI).

encodeuricomponent (encodeduristring)

The required encodeduristring parameter represents an encoded URI component. Description

The encodeURIComponent method returns an encoded URI. If you pass the encoding result to decodeuricomponent, the original string is returned. Because the encodeuricomponent method encodes all characters, note that if the string represents a path, such as/folder1/folder2/default.html, the slash will also be encoded. This will not be valid when the encoding result is sent as a request to the Web server. If the string contains more than one URI component, use the encodeURI method to encode it.


Escape Method
Returns a coded String that can be read on all computers
Object .

function Escape (charstring:string): String
Parameters
Charstring
Must be selected. Any String object or text to encode.
Note
The Escape method returns a string value (Unicode format) that contains charstring content. All spaces, punctuation, accent marks, and any
otherNon-ASCII characters are replaced with%XX encoding, where xx equals the hexadecimal number that represents the character. For example, the space is returned as.

Characters with a character value greater than 255 are stored in%UXXXX format.

Note The escape method cannot be used to encode a Uniform Resource Identifier (URI). The encodeURI and encodeURIComponent methods should be used for encoding.
Requirements
Version 1

Please see
encodeURI Method | encodeURIComponent Method | String Object | Method

Apply to: Global Object

encodeURI Method
Returns a string that is encoded as a valid Uniform Resource Identifier (URI).

function encodeURI (uristring:string): String
Parameters
Uristring
Must be selected. A string representing the encoded URI.
Note
The encodeURI method returns an encoded URI. If the encoding result is passed to decodeURI, the initial string is returned. encodeURI does not encode the following characters: ":", "/", ";" and "?". Use encodeURIComponent to encode these characters.

Requirements
Version 5.5

Please see
decodeURI Method | decodeURIComponent method

Apply to: Global Object

encodeURIComponent Method
Returns a string of valid components encoded as a Uniform Resource Identifier (URI).

function encodeURIComponent (encodeduristring:string): String
Parameters
Encodeduristring
Must be selected. A string representing the encoded URI component.
Note
The encodeURIComponent method returns an encoded URI. If the encoding result is passed to decodeURIComponent, the initial string is returned. Because the encodeURIComponent method will encode all characters, note that if the string represents a path, such as/folder1/folder2/default.html, the slash will also be encoded so that when the string is sent as a request to the Web It will be invalid when the server is in use. If the string contains more than one URI component, use the encodeURI method to encode it.

Requirements
Version 5.5

Please see
decodeURI Method | decodeURIComponent method

Apply to: Global Object

Method
Returns the decoded string from a string object encoded with the escape method.

function (charstring:string): String
Parameters
Charstring
Must be selected. The String object or text to decode.
Note
method returns a String value containing the charstring content. All characters encoded in%XX 16 are replaced with the equivalent characters in the ASCII character set.

Characters encoded in%UXXXX format (Unicode characters) are replaced with Unicode characters in hexadecimal-encoded XXXX.

Note The method should not be used to decode the Uniform Resource Identifier (URI). Use the decodeURI and decodeURIComponent methods instead.
Requirements
Version 1

Please see
decodeURI Method | decodeURIComponent Method | Escape Method | String Object

Apply to: Global Object

decodeURI Method
Returns the encoded form of a Uniform Resource Identifier (URI).

function decodeURI (uristring:string): String
Parameters
Uristring
Must be selected. A string representing the encoded URI.
Note
Use the decodeURI method instead of obsolete methods.

The decodeURI method returns a string value.

If the uristring is invalid, urierror will occur.

Requirements
Version 5.5

Please see
decodeURIComponent Method | encodeURI method

Apply to: Global Object

decodeURIComponent Method
Returns the non-encoded form of an encoded component of a Uniform Resource Identifier (URI).

function decodeURIComponent (encodeduristring:string): String
The required encodeduristring parameter is a value that represents the encoded URI component.

Note
Uricomponent is part of a complete URI.

If the encodeduristring is invalid, a urierror is generated.

Requirements
Version 5.5

Please see
decodeURI Method | encodeURI method


Turn from: http://www.cnblogs.com/xiurui12345/archive/2012/05/16/2503887.html

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.