URL Encoding __ Code

Source: Internet
Author: User

Http://www.cnblogs.com/lovablebox/archive/2007/12/03/981307.html URL encoding method comparison Encode,javascript,escape,encodeuri , there are several ways to encode URL strings in encodeuricomponent,utf-8 javascript: Escape (), encodeURI (), and encodeURIComponent (). These encodings play a different role.
Escape () method:

Encodes the specified string with the ISO Latin character set. All spaces, punctuation, special characters, and other non-ASCII characters will be converted into%XX-formatted character encodings (XX equals the encoded 16 digits of the character in the character set table). For example, spaces's corresponding encoding is%20. The character that

will not be encoded by this method: @ */+

encodeURI () method:

Converts a URI string into a string in an escape format using the UTF-8 encoding format. The character that

will not be encoded by this method:! @ # $& * () =:/;? + '

encodeURIComponent () method:

Converts a URI string into e using UTF-8 encoding format A string in scape format. This method encodes more characters than encodeURI (), such as/or characters. So if a string contains several parts of the URI, this method cannot be encoded, otherwise the URL will display an error after the/character is encoded. The character that

will not be encoded by this method:! * () '

Therefore, for Chinese strings, if you do not want to convert the string encoding format to UTF-8 format (such as the original page and the target page of the charset is consistent), you only need to use escape. If your page is GB2312 or other code, and the page that accepts the parameter is UTF-8 encoded, you should use encodeURI or encodeuricomponent.

In addition, Encodeuri/encodeuricomponent was introduced after javascript1.5, and escape is available in the javascript1.0 version.

 

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.