URL encoding parameters in JS (urlencode)

Source: Internet
Author: User

There are a lot of text files written on the Internet that are used to present user-defined parameters when rendering functions similar to urlencode in JS. In fact, JS itself has such parameters.
The parameter is passed in a URL-like format, so do not assign values directly.
The following is a summary of the URL encoding of variable values: encodeuricomponent (), get, and post methods can both be used to send
In Java programming scripts, there are several tips for stopping the encoding of URL strings: escape (), encodeuri (), and encodeuricomponent (). The functions of these encodings are different.
Escape () tips:
The specified string is not encoded using the ISO Latin character set. All space characters, punctuation marks, special characters, and more non-ASCII characters that are associated with each other will be converted into % XX character encodings (XX equals to the 16 encoding of the character in the character set table number ). For example, the space character is encoded as % 20.
Characters not encoded by this tip: @ */+
Encodeuri () tips:
Convert URI strings into various types of escape strings encoded in UTF-8.
Characters not encoded by this tip :! @ # $ & * () = :/;? +'
Encodeuricomponent () tips:
Convert URI strings into various types of escape strings encoded in UTF-8. Compared with encodeuri (), the trick will stop encoding more characters, such. So if the string contains several parts of the URI, do not stop encoding with that trick. Otherwise, the URL will be incorrectly rendered after the/character is encoded.
Characters not encoded by this tip :! *()'

Therefore, for Chinese strings, if you do not want to convert string encoding to various types of UTF-8 (such as the original page and the target page charset is consistent), only need to apply escape. If your page is gb2312 or more associated encoding, and the page that accepts the parameter is UTF-8 encoding, use encodeuri or encodeuricomponent.

 

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.