使用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正則
var r20 = /%20/g,
jQuery.param方法中會(huì)將所有的"%20"轉(zhuǎn)成"+",即提交數(shù)據(jù)前,數(shù)據(jù)中如果包含空格,那經(jīng)過(guò)encodeURIComponent后,空格會(huì)轉(zhuǎn)成"%20"
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
復(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)文章
JavaScript極簡(jiǎn)入門(mén)教程(三):數(shù)組
這篇文章主要介紹了JavaScript極簡(jiǎn)入門(mén)教程(二):數(shù)組,本文主要講解了數(shù)組的創(chuàng)建和length屬性的介紹,其它方法屬性都沒(méi)有介紹,需要的朋友可以參考下2014-10-10在IE和VB中支持png圖片透明效果的實(shí)現(xiàn)方法(vb源碼打包)
在IE和VB中支持png圖片透明效果的實(shí)現(xiàn)方法(vb源碼打包),需要的朋友可以參考下。2011-04-04javascript省市區(qū)三級(jí)聯(lián)動(dòng)下拉框菜單實(shí)例演示
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)省市區(qū)三級(jí)聯(lián)動(dòng)下拉框菜單很詳細(xì)的代碼,解決了大家實(shí)現(xiàn)javascript省市區(qū)三級(jí)聯(lián)動(dòng)下拉框菜單的問(wèn)題,感興趣的小伙伴們可以參考一下2015-11-11mui框架 頁(yè)面無(wú)法滾動(dòng)的解決方法(推薦)
下面小編就為大家分享一篇mui框架 頁(yè)面無(wú)法滾動(dòng)的解決方法(推薦),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01