Home  >  Article  >  Web Front-end  >  How does JavaScript solve the problem of Chinese garbled URLs?

How does JavaScript solve the problem of Chinese garbled URLs?

coldplay.xixi
coldplay.xixiOriginal
2021-04-30 14:28:423241browse

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.

How does JavaScript solve the problem of Chinese garbled URLs?

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:

javascript video tutorial

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn