当前位置:网站首页>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
边栏推荐
- Change the material of unity model as a whole
- LeetCode 74、搜索二维矩阵
- Some basic knowledge of devexpress report development
- Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
- [target tracking] pedestrian attitude recognition based on frame difference method combined with Kalman filter, with matlab code
- CVPR 2022 | querydet: use cascaded sparse query to accelerate small target detection under high resolution
- The R language uses the timeroc package to calculate the multi time AUC value of survival data without competitive risk, and uses the confint function to calculate the confidence interval value of mul
- Devexpress 14.1 installation record
- Rt-1052 learning notes - GPIO architecture analysis
- selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
猜你喜欢

go-zero框架数据库方面避坑指南

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

Linux64Bit下安装MySQL5.6-不能修改root密码

波场DAO新物种下场,USDD如何破局稳定币市场?
![[talkative cloud native] load balancing - the passenger flow of small restaurants has increased](/img/ba/4ccf0c2181572fed16bbc9c797d557.png)
[talkative cloud native] load balancing - the passenger flow of small restaurants has increased

LeetCode 74、搜索二维矩阵

selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT

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

Leetcode dynamic planning training camp (1-5 days)

Monte Carlo py solves the area problem! (save pupils Series)
随机推荐
How about CICC fortune? Is it safe to open an account
Some basic configurations in interlij idea
Scripy tutorial - (2) write a simple crawler
[graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Plato Farm元宇宙IEO上线四大,链上交易颇高
Identification of bolt points in aerial photography based on perception
Thirty What are VM and VC?
The R language uses the timeroc package to calculate the multi time AUC value of survival data without competitive risk, and uses the confint function to calculate the confidence interval value of mul
Numpy - creation of data type and array
Recognition of high-speed road signs by Matlab using alexnet
Common form verification
SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
[stack and queue topics] - sliding window
R language ggplot2 visualization: ggplot2 visualizes the scatter diagram and uses geom_ mark_ The ellipse function adds ellipses around data points of data clusters or data groups for annotation
LeetCode 1337、矩阵中战斗力最弱的 K 行
How to do product innovation—— Exploration of product innovation methodology I
Analysis of the relationship between generalized Bim and CAD under the current background
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case