当前位置:网站首页>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
边栏推荐
- R language uses econocrats package to create microeconomic or macroeconomic map, visualize indifference function indifference curve, customize calculation intersection, and customize the parameters of
- Servlet learning notes
- R language ggplot2 visual facet_wrap, and use the lineheight parameter to customize the height of the facet icon tab (gray label bar)
- bounding box iou
- Automatically fill in body temperature and win10 task plan
- Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
- 6-5 字符串 - 2. 字符串复制(赋值) (10 分)C语言标准函数库中包括 strcpy 函数,用于字符串复制(赋值)。作为练习,我们自己编写一个功能与之相同的函数。
- 三十.什么是vm和vc?
- Identification of bolt points in aerial photography based on perception
- An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
猜你喜欢
Servlet learning notes
selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
Customize timeline component styles
Some basic configurations in interlij idea
DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
Redis cache penetration, cache breakdown, cache avalanche
How can matlab obtain the truncated image in trainingimagelabeler
WordPress插件:WP-China-Yes解决国内访问官网慢的方法
[target tracking] pedestrian attitude recognition based on frame difference method combined with Kalman filter, with matlab code
DTMF dual tone multi frequency signal simulation demonstration system
随机推荐
I JS deep copy and shallow copy
Numpy Index & slice & iteration
Introduction to link database function of cadence OrCAD capture CIS replacement components, graphic tutorial and video demonstration
Experience of mathematical modeling in 18 year research competition
. Ren -- the intimate artifact in the field of vertical Recruitment!
Building the tide, building the foundation and winning the future -- the successful holding of zdns Partner Conference
JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files
Numpy sort search count set
一. js的深拷贝和浅拷贝
How do BIM swindlers cheat? (turn)
The flinkcdc reports an error: but this is no longer available on the server
[latex] 5 how to quickly write out the latex formula corresponding to the formula
Solution to PowerDesigner's failure to connect to MySQL in x64 system
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
DNS cloud school rising posture! Three advanced uses of authoritative DNS
PCL点云处理之基于PCA的几何形状特征计算(五十二)
波场DAO新物种下场,USDD如何破局稳定币市场?
LeetCode 994、腐烂的橘子
Linux64Bit下安装MySQL5.6-不能修改root密码
How does onlyoffice solve no route to host