当前位置:网站首页>JS URLEncode function
JS URLEncode function
2022-07-25 15:26:00 【Henry_ Nan】
The perfect js URLEncode function
When you need to pass the value to the server through the query string, you need to get Parameters encode.
- escape() function , Can't encode
@*/+( It is not recommended to use ) - encodeURI() function , Can't encode
[email protected]#$&*()=:/,;?+'( It is not recommended to use ) - encodeURIComponent() function , Can't encode
~!*()This function is the most commonly used
We need to be right about encodeURIComponent function , The least modification :
function urlencode (str) {
str = (str + '').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
PS: For example, wechat H5 The parameters of the callback page are required in the payment redirect_url Parameters URLEncode.
Front end routing adopts hash Pattern , Because I used encodeURI, Lead to # not encode And cause # Loss of subsequent content , use encodeURIComponent Just fine
边栏推荐
- Promise object and macro task, micro task
- 请问seata中mysql参数每个客户端连接最大的错误允许数量要怎么理解呢?
- Object.prototype. Hasownproperty() and in
- 异步fifo的实现
- Spark 内存管理机制 新版
- Spark 判断DF为空
- matlab---错误使用 var 数据类型无效。第一个输入参数必须为单精度值或双精度值
- Vscode plugin collection
- redis淘汰策列
- C language function review (pass value and address [binary search], recursion [factorial, Hanoi Tower, etc.))
猜你喜欢

How to solve the login problem after the 30 day experience period of visual stuido2019

Spark SQL null value, Nan judgment and processing

Outline and box shadow to achieve the highlight effect of contour fillet

4PAM在高斯信道与瑞利信道下的基带仿真系统实验

从 join on 和 where 执行顺序认识T-sql查询执行顺序

wait()和sleep()的区别理解

Simulate setinterval timer with setTimeout

ML - 语音 - 传统语音模型

分布式原理 - 什么是分布式系统

Recommend 10 learning websites that can be called artifact
随机推荐
Implementation of asynchronous FIFO
What is the Internet of things
Image cropper example
反射-笔记
UITextField的inputView和inputAccessoryView注意点
Redis elimination strategy list
Browser workflow (Simplified)
UIDocumentInteractionController UIDocumentPickerViewController
C language function review (pass value and address [binary search], recursion [factorial, Hanoi Tower, etc.))
The implementation process of inheritance and the difference between Es5 and ES6 implementation
ML - 语音 - 语音处理介绍
用OpenPose进行单个或多个人体姿态估计
伤透脑筋的CPU 上下文切换
PageHelper does not take effect, and SQL does not automatically add limit
从 join on 和 where 执行顺序认识T-sql查询执行顺序
spark分区算子partitionBy、coalesce、repartition
Flex 布局
在网页上实现任意格式的音视频快速播放功能的开发总结。
The number of query results of maxcompute SQL is limited to 1W
Es5 thinking of writing inheritance