当前位置:网站首页>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
边栏推荐
- [latex] 5 how to quickly write out the latex formula corresponding to the formula
- [PTA] l1-002 printing hourglass
- Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
- [problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
- 2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real
- selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
- Es error: request contains unrecognized parameter [ignore_throttled]
- Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
- SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
- LeetCode 20、有效的括号
猜你喜欢

Livego + ffmpeg + RTMP + flvjs to realize live video

2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real

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

Installation and use of NVM

SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
![[graph theory brush question-4] force deduction 778 Swimming in a rising pool](/img/e3/a8cd9fc7773843e9e8ee6a6eba123f.png)
[graph theory brush question-4] force deduction 778 Swimming in a rising pool

Some basic knowledge of devexpress report development

Scripy tutorial - (2) write a simple crawler

Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high

Matlab analytic hierarchy process to quickly calculate the weight
随机推荐
BMP JPEG 图片转换为矢量图像 ContourTrace
PCL点云处理之直线与平面的交点计算(五十三)
Solution to PowerDesigner's failure to connect to MySQL in x64 system
Scripy tutorial - (2) write a simple crawler
论文写作 19: 会议论文与期刊论文的区别
The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
What is the difference between a host and a server?
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
JDBC tool class jdbcconutil gets the connection to the database
LeetCode 1337、矩阵中战斗力最弱的 K 行
On BIM data redundancy theory
Development of Matlab GUI bridge auxiliary Designer (functional introduction)
Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
【栈和队列专题】—— 滑动窗口
Computing the intersection of two planes in PCL point cloud processing (51)
Automatically fill in body temperature and win10 task plan
bounding box iou
Still using listview? Use animatedlist to make list elements move
R language ggplot2 visual facet_wrap, and use the lineheight parameter to customize the height of the facet icon tab (gray label bar)