当前位置:网站首页>js URLEncode函数
js URLEncode函数
2022-07-25 15:00:00 【Henry_楠】
完美的js URLEncode函数
当需要通过查询字符串传值给服务器时需要对get参数进行encode。
- escape()函数,不会encode
@*/+(不推荐使用) - encodeURI()函数,不会encode
[email protected]#$&*()=:/,;?+'(不推荐使用) - encodeURIComponent()函数,不会encode
~!*()这个函数是最常用的
我们需要对encodeURIComponent函数,最一点修改:
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:例如微信H5支付中要求对回调页面的参数redirect_url参数进行 URLEncode。
前端路由采用了hash模式,由于我采用的是encodeURI,导致 # 未 encode而引起#后面内容的丢失,采用encodeURIComponent就好了
边栏推荐
- Yarn: the file yarn.ps1 cannot be loaded because running scripts is prohibited on this system.
- 32 chrome调试工具的使用
- Splice a field of the list set into a single string
- spark参数调整调优
- (original) customize a scrolling recyclerview
- Kibana operation es
- MySQL 45讲 | 06 全局锁和表锁 :给表加个字段怎么有这么多阻碍?
- Bridge NF call ip6tables is an unknown key exception handling
- 【MySQL系列】-索引知多少
- 006 operator introduction
猜你喜欢

SPI传输出现数据与时钟不匹配延后问题分析与解决
![[MySQL series] - how much do you know about the index](/img/d7/5045a846580be106e2bf16d7b30581.png)
[MySQL series] - how much do you know about the index

6线SPI传输模式探索
![[Nacos] what does nacosclient do during service registration](/img/76/3c2e8f9ba19e36d9581f34fda65923.png)
[Nacos] what does nacosclient do during service registration

流程控制(上)
![Number of high-quality number pairs [bit operation characteristics + abstract ability evaluation + grouping fast statistics]](/img/c9/8f8f0934111f7ae8f8abd656d92f12.png)
Number of high-quality number pairs [bit operation characteristics + abstract ability evaluation + grouping fast statistics]

37 元素模式(行内元素,块元素,行内块元素)

06、类神经网络

Go language founder leaves Google

44 新浪导航 ,小米边栏 练习
随机推荐
51 single chip microcomputer learning notes (1)
Log4j2 basic configuration
Several methods of spark parameter configuration
Splice a field of the list set into a single string
[C topic] force buckle 876. Intermediate node of linked list
Syntax summary of easygui
[C题目]力扣88. 合并两个有序数组
06、类神经网络
Ssh server rejected password
Thymeleaf notes
Melody + realsense d435i configuration and error resolution
二维数组赋初值你会几种方法?
Deployment and simple use of PostgreSQL learning
[thread knowledge points] - spin lock
IP address classification, which determines whether a network segment is a subnet supernetwork
spark参数调整调优
Gonzalez Digital Image Processing Chapter 1 Introduction
44 新浪导航 ,小米边栏 练习
IP地址分类,判断一个网段是子网超网
Install entityframework method