URL encoding and decoding

Source: Internet
Author: User

When using JS to pass parameters between each HTML page, some special words nginx in the past to receive the problem, the best way is to pass the parameters before encoding, received and then decoded. Collected a few of the commonly used functions

1.escape

Http://www.w3school.com.cn/jsref/jsref_escape.asp

2.encodeURI

Http://www.w3school.com.cn/jsref/jsref_encodeuri.asp

3.encodeURIComponent

Http://www.w3school.com.cn/jsref/jsref_encodeURIComponent.asp

Got a little information about their differences.

Escape () cannot be used directly for URL encoding, and its true function is to return a Unicode encoded value of a character. For example, "Spring Festival" return result is%u6625%u8282,,escape () not "+" coding is mainly used for Chinese character coding, now is not advocated for use.

encodeURI () is a function in JavaScript that is really used to encode URLs. Encode the entire URL address, but to the special meaning of the symbol "; / ? : @ & = + $, # ", also not encoded. The corresponding decoding function is: decodeURI ().

encodeURIComponent () can encode "; / ? : @ & = + $, # "these special characters. The corresponding decoding function is decodeURIComponent (). If you want to pass the URL with the & symbol, use encodeURIComponent ()

URL encoding and decoding

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.