I. garbled characters are transmitted in JS URLs. Key points: encodeuri encoding and decodeuri decoding:

Source: Internet
Author: User

I. garbled characters are transmitted in JS URLs. Key points: encodeuri encoding and decodeuri decoding:

1. parameter passing page
JavaScript code: <SCRIPT type = "text/JavaScript"> // <! [CDATA [
Function send (){
VaR url = "test01.html ";
VaR username = $ ("# username" ).html ();
Window. Open (encodeuri (URL + "? Username = "+ username ));}
//]>
</SCRIPT>

2. Receiving parameters page: test02.html

<SCRIPT>
VaR urlinfo = Window. Location. href; // retrieve the URL
VaR username = urlinfo. Split ("?") [1]. Split ("=") [1]; // The number of shards after the split URL is "="
Users (includomainusernamedomain.html .html (decodeuri (username ));
</SCRIPT>
Ii. How to obtain the URL "?" Then, the "=" parameter value:

A. First, use window. Location. href to get all URL values.
B. Use split to intercept "?" All
C. Split ("?") The number in [1] after it is calculated from 0 by default.

Iii. Differences between escape, Unescape, encodeuri and encodeuricomponent in JS:

1. When passing parameters, encodeuricomponent. Otherwise, the URL is easily marked "#","?"," And other sensitive symbols.
2. Used for URL jump, encoding using encodeuri, and decoding using decodeuri.
3. Escape () is only for ASCII characters other than 0-conversion, converted to % u *** such code, if you want to use more characters such as UTF-8 Character Library
You must use encodeuricomponent () or encodeuri () to convert it to % NN.
This code can be used. In other cases, escape, encodeuri, and encodeuricomponent have the same encoding results. Therefore, for the global unification process
Use encodeuricomponent () or encodeuri () instead of escape!

You can reprint it as needed. During reprinting, be sure to mark the original source of the article and the statement in the form of a hyperlink.

Address: http://www.weiking.com.cn/post/654.html

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.