Javascript method to solve the problem of Chinese garbled URLs: 1. Use encodeURI to encode the entire parameters of the transmitted page; 2. Use decodeURI to decode the entire parameters of the receiving page.
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Javascript method to solve the problem of Chinese garbled URLs:
1. The page passed:
encodeURI(url + "?userName=" + userName);
//encodeURI is for Encode the entire parameter
url + "?userName=" + encodeURIComponent(userName);
//encodeURIComponent encodes a single parameter
2. Receive page:
$("#id").html(decodeURI(userName));
/ /decodeURI decodes the entire parameter
$("#id").html(decodeURIComponent(userName));
//decodeURIComponent decodes a single parameter
##Related free learning recommendations:
The above is the detailed content of How does JavaScript solve the problem of Chinese garbled URLs?. For more information, please follow other related articles on the PHP Chinese website!