JS Code encodeuricomponent Use Introduction (asp,php) _javascript tips

Source: Internet
Author: User
Because of the new system, so for the JS script again studied again. In the new URL encoding, found that the format of the page encoding for JS is very large, write a little here.

{var b=siteurl+this.actionurl+ (this.type=== "All"? ": This.type) +" &searchword= "+encodeuricomponent (A). Replace (/'/g, "%27"); $redirect (B)}}

In the production, found that outgoing packets of the encoding is all UTF-8 format, and in the correction of the page encoding is also not reflected, and finally modified the encode into a decode way to solve the problem.

JS encoding text involves 3 functions: Escape,encodeuri,encodeuricomponent, corresponding 3 decoding functions: Unescape,decodeuri,decodeuricomponent


1, the transfer of parameters need to use encodeuricomponent, so that the combination of the URL will not be # and other special characters truncated.

For example:

2, the URL jump can be used as a whole encodeURI

For example: location.href= "/encodeuri" ("http://www.jb51.net/s?word= Baidu &ct=21");

3, JS use of data can use escape

For example: History records in the search of Tibet.

4, Escape to encode the Unicode value other than 0-255, output%u**** format, in other cases escape,encodeuri,encodeuricomponent encoding results are the same.

The most used should be encodeuricomponent, it is the Chinese, Korean and other special characters into the Utf-8 format URL encoding, so if the background pass parameters need to use encodeURIComponent when the background decoding to Utf-8 support ( form is encoded in the same way as the current page encoding

Escape does not encode 69 characters: *,+,-,.,/,@,_,0-9,a-z,a-z

There are 82 encodeURI characters not encoded:!,#,$,&,\ ', (,), *,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,a-z

There are 71 encodeuricomponent characters that are not encoded:!, \ ', (,), *,-,.,_,~,0-9,a-z,a-z
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.