(Recommended) use JavaScript top-level functions to encode URLs

Source: Internet
Author: User

If the form action is list. Do? Act = Go & State = 5
Then, the request. getparameter method is used to obtain the values of act and state.
If you want to upload 'go & State = 5' as a string, act = 'go & State = 5' contains ;/? : @ & =+ $, # Special characters that have special meanings in Uris.
To get the exact act value 'go & State = 5' on the server side, You must escape special characters such as & =.

Top-level functions of JavaScript (global functions ):
The encodeuricomponent () function can encode a string as a "part" of the URI. For example, if 'go & State = 5' is encoded, it will be ;/? : @ & =+ $, # Encode
The encodeuri () function can encode a string as an "1 whole" URI. For example,/my first/list. jsp? A = 12 & B = 45 & C = 89, & is the parameter separator, so it is not true ;/? : @ & =+ $, # Encode

The decodeuricomponent () function can decode the uri of the encodeuricomponent () function.
The decodeuri () function can decode the URI encoded by the encodeuri () function.

Example:

JSCode
Encodeuricomponent (",/? : @ & =+ $ # ") Returned result: % 2C % 2f % 3f % 3A % 40% 3D % 2B % 26% 23
Encodeuricomponent ("http://www.w3school.com.cn/P 1/") returned results: HTTP % 3A % 2f % 2fwww.w3school.com.cn % 2fp % 201% 2f

Encodeuri (",/? : @ & = + $ # ") Returned result :,/? : @ & =+ $ #
Encodeuri ("http://www.w3school.com.cn/My first/") returned results: http://www.w3school.com.cn/My%20first/

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.