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

How does JavaScript solve the problem of Chinese garbled URLs?

coldplay.xixi
Release: 2023-01-05 16:13:15
Original
3298 people have browsed it

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);
Copy after login

//encodeURI is for Encode the entire parameter

url + "?userName=" + encodeURIComponent(userName);
Copy after login

//encodeURIComponent encodes a single parameter

2. Receive page:

$("#id").html(decodeURI(userName));
Copy after login

/ /decodeURI decodes the entire parameter

$("#id").html(decodeURIComponent(userName));
Copy after login

//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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template