当前位置:网站首页>Solve the Chinese garbled code of URL in JS - decoding
Solve the Chinese garbled code of URL in JS - decoding
2022-04-23 20:24:00 【First code】
solve url The statement , There are three main ways :unescape,encodeURI as well as encodeURIComponent(), about url It contains Chinese , It was found that the previously used did not work , Changed to decodeURL Chinese decoding is normal , The code is as follows
var url = window.location.search; // obtain url in "?" The string after the sign
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
// That's the problem with this sentence
console.log( theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]));
// I used it before unescape()
// There will be garbled code
}
}
Code encapsulation reference
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // Construct a regular expression object with target parameters
var r = window.location.search.substr(1).match(reg); // Match target parameters
if (r != null) return decodeURI(r[2]);
return null; // Return parameter value
}
getUrlParam( Parameters 1);
getUrlParam( Parameters 2);
版权声明
本文为[First code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210551267745.html
边栏推荐
- LeetCode 1346、检查整数及其两倍数是否存在
- 論文寫作 19: 會議論文與期刊論文的區別
- go-zero框架数据库方面避坑指南
- Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
- 一. js的深拷贝和浅拷贝
- 如何做产品创新?——产品创新方法论探索一
- Mysql database backup scheme
- SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
- Redis distributed lock
- Building the tide, building the foundation and winning the future -- the successful holding of zdns Partner Conference
猜你喜欢

Three. Based on ply format point cloud voxel model JS upload interface writing

Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)

Monte Carlo py solves the area problem! (save pupils Series)

Installation and use of NVM

SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions

Plato Farm元宇宙IEO上线四大,链上交易颇高

Shanghai a répondu que « le site officiel de la farine est illégal »: l'exploitation et l'entretien négligents ont été « noirs » et la police a déposé une plainte

PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)

BMP JPEG 图片转换为矢量图像 ContourTrace

Browser - learning notes
随机推荐
[graph theory brush question-4] force deduction 778 Swimming in a rising pool
【PTA】L1-002 打印沙漏
Experience of mathematical modeling in 18 year research competition
Paper writing 19: the difference between conference papers and journal papers
Cadence Orcad Capture 批量更改元件封装功能介绍图文教程及视频演示
Redis installation (centos7 command line installation)
[PTA] l1-002 printing hourglass
Es index (document name) fuzzy query method (database name fuzzy query method)
PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 127
Mysql database and table building: the difference between utf8 and utf8mb4
R language uses econocrats package to create microeconomic or macroeconomic map, visualize indifference function indifference curve, customize calculation intersection, and customize the parameters of
SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
A useless confession artifact
LeetCode 994、腐烂的橘子
2022dasctf APR x fat epidemic prevention challenge crypto easy_ real
PCA based geometric feature calculation of PCL point cloud processing (52)
Alicloud: could not connect to SMTP host: SMTP 163.com, port: 25
一. js的深拷贝和浅拷贝
波场DAO新物种下场,USDD如何破局稳定币市场?