欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用Post提交時(shí)須將空格轉(zhuǎn)換成加號(hào)的解釋

 更新時(shí)間:2013年01月14日 17:20:02   作者:  
參數(shù)有中包含空格且使用Post提交時(shí)須將空格轉(zhuǎn)換成加號(hào),這樣后臺(tái)程序接受到的才是真正的空格,感興趣的朋友可以了解下
jQuery的serialize模塊中有個(gè)r20正則
復(fù)制代碼 代碼如下:

var r20 = /%20/g,

jQuery.param方法中會(huì)將所有的"%20"轉(zhuǎn)成"+",即提交數(shù)據(jù)前,數(shù)據(jù)中如果包含空格,那經(jīng)過(guò)encodeURIComponent后,空格會(huì)轉(zhuǎn)成"%20"
復(fù)制代碼 代碼如下:

encodeURIComponent(' ') === '%20'; // true

最后需要將"%20"轉(zhuǎn)換成"="再Post提交。這樣后臺(tái)程序接受到的才是真正的空格。

關(guān)于 encodeURIComponent,見(jiàn)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 "+".

相關(guān)
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
http://www.w3.org/TR/html401/interact/forms.html#form-content-type

相關(guān)文章

最新評(píng)論