使用Post提交时须将空格转换成加号的解释
时间:2023-07-02 05:18:19
jQuery的serialize模块中有个r20正则
var r20 = /%20/g,
jQuery.param方法中会将所有的"%20"转成"+",即提交数据前,数据中如果包含空格,那经过encodeURIComponent后,空格会转成"%20"
encodeURIComponent(' ') === '%20'; // true
最后需要将"%20"转换成"="再Post提交。这样后台程序接受到的才是真正的空格。
关于 encodeURIComponent,见MDC描述
encodeURIComponent escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )
To avoid unexpected requests to the server, you should call encodeURIComponent on any user-entered parameters that will be passed as part of a URI. For example, a user could type "Thyme &time=again" for a variable comment. Not using encodeURIComponent on this variable will give comment=Thyme%20&time=again. Note that the ampersand and the equal sign mark a new key and value pair. So instead of having a POST comment key equal to "Thyme &time=again", you have two POST keys, one equal to "Thyme " and another (time) equal to again.
For application/x-www-form-urlencoded (POST), per http://www.w3.org/TR/html401/interac...m-content-type, spaces are to be replaced by '+', so one may wish to follow a encodeURIComponent replacement with an additional replacement of "%20" with "+".
相关:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
http://www.w3.org/TR/html401/interact/forms.html#form-content-type
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server数据库复制失败的原因及解决方法
![](https://img.aspxhome.com/file/2023/6/107686_0s.png)
python3中TQDM库安装及使用详解
![](https://img.aspxhome.com/file/2023/2/86322_0s.png)
python基础之文件操作
![](https://img.aspxhome.com/file/2023/9/112149_0s.png)
Pivot,信息组织的梦想之窗
![](https://img.aspxhome.com/file/UploadPic/20101/11/pivot-01-87s.jpg)
python中的json数据和pyecharts模块入门示例教程
![](https://img.aspxhome.com/file/2023/9/87659_0s.jpg)
详解Docker创建Mysql容器并通过命令行连接到容器
分享216色网页拾色器(调色板)
![](https://img.aspxhome.com/file/UploadPic/20079/27/2007927124954557s.jpg)
Laravel实现ApiToken认证请求
![](https://img.aspxhome.com/file/2023/7/92817_0s.jpg)
简单介绍Python中的RSS处理
jupyter notebook参数化运行python方式
![](https://img.aspxhome.com/file/2023/1/70111_0s.jpg)
Python与Matlab混合编程的实现案例
![](https://img.aspxhome.com/file/2023/7/103467_0s.png)
Django REST Framework之频率限制的使用
![](https://img.aspxhome.com/file/2023/3/124243_0s.jpg)
3行Python代码实现图像照片抠图和换底色的方法
![](https://img.aspxhome.com/file/2023/1/99611_0s.jpg)
纯CSS Tooltips提示
用Python实现插值算法
![](https://img.aspxhome.com/file/2023/0/128490_0s.png)
详解MySQL数据库安全配置
Python使用OpenCV对图像进行缩放功能
![](https://img.aspxhome.com/file/2023/7/71357_0s.jpg)
PyQt4编程之让状态栏显示信息的方法
python神经网络InceptionV3模型复现详解
![](https://img.aspxhome.com/file/2023/8/123458_0s.png)