使用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

标签:Post提交,空格,加号
0
投稿

猜你喜欢

  • SQL Server数据库复制失败的原因及解决方法

    2024-01-17 20:35:50
  • python3中TQDM库安装及使用详解

    2023-02-17 20:05:55
  • python基础之文件操作

    2022-12-23 01:15:53
  • Pivot,信息组织的梦想之窗

    2009-12-25 14:32:00
  • python中的json数据和pyecharts模块入门示例教程

    2023-02-22 04:58:37
  • 详解Docker创建Mysql容器并通过命令行连接到容器

    2024-01-24 22:25:18
  • 分享216色网页拾色器(调色板)

    2007-09-27 12:33:00
  • Laravel实现ApiToken认证请求

    2023-11-24 10:35:48
  • 简单介绍Python中的RSS处理

    2023-03-03 13:59:17
  • jupyter notebook参数化运行python方式

    2022-09-10 21:38:55
  • Python与Matlab混合编程的实现案例

    2023-01-14 14:44:39
  • Django REST Framework之频率限制的使用

    2021-01-25 17:59:42
  • 3行Python代码实现图像照片抠图和换底色的方法

    2021-12-11 04:57:35
  • 纯CSS Tooltips提示

    2008-10-18 16:01:00
  • 用Python实现插值算法

    2021-07-16 11:01:22
  • 详解MySQL数据库安全配置

    2010-01-26 15:19:00
  • Python使用OpenCV对图像进行缩放功能

    2022-05-06 03:47:51
  • PyQt4编程之让状态栏显示信息的方法

    2021-07-22 04:11:19
  • python神经网络InceptionV3模型复现详解

    2021-05-29 16:53:01
  • Python实现葵花8号卫星数据自动下载实例

    2021-09-26 13:40:25
  • asp之家 网络编程 m.aspxhome.com