国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

使用Post提交時須將空格轉換成加號的解釋

2024-05-06 14:19:59
字體:
來源:轉載
供稿:網友
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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 白朗县| 滦南县| 晋江市| 唐河县| 南靖县| 涟水县| 鄂尔多斯市| 合阳县| 乐陵市| 望奎县| 阿拉尔市| 西乌| 孙吴县| 鹤山市| 元阳县| 贡嘎县| 同仁县| 若尔盖县| 玛曲县| 黄冈市| 天峨县| 五莲县| 萝北县| 双流县| 花垣县| 西乌珠穆沁旗| 眉山市| 饶平县| 陵川县| 华容县| 类乌齐县| 怀来县| 陈巴尔虎旗| 林口县| 敦煌市| 平江县| 正安县| 金川县| 瑞安市| 自贡市| 原阳县|