JS processing URL Practical Tips

Source: Internet
Author: User
Escape (), encodeURI (), encodeURIComponent () Three methods can filter some special characters that affect URL integrity. But the latter two is the way to convert the string to UTF-8, which solves the problem of garbled page encoding.

For example: The sending page is inconsistent with the encoding format (Charset) of the Accept page (assuming that the sending page is GB2312 and the receiving page encoding is UTF-8), and using the escape () conversion will cause garbled problems with the text string in transit.
Here are the various ways to encode/decode URLs under JS:

Escape method: For @*+/A-Z 0-9 A-Z These characters are not encoded, other non-ASCII characters are encoded to%XX encoding substitution, decoding using the Unescape,escape method cannot be used to encode a "Uniform Resource Identifier" (URI). The encoding should use the encodeURI and encodeURIComponent methods. encodeURI (): Yes! @ # $ & * () =:/;? + ' A-Z 0-9 A-Z, other characters will be encoded, decoded using decodeURI ();

If you want to make more words to be encoded, for example:/, use the encodeURIComponent () method, after being encoded by this method, the parameter passed to the server is an invalid character, decoding using decodeURIComponent ()

JS processing URL Practical Tips

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.