複製程式碼 程式碼如下:
jQuery.param方法中會將所有的" "轉成" ",即提交資料前,資料中如果包含空格,那經過encodeURIComponent後,空格會轉成" "
複製程式碼
程式碼如下: encodeURIonent(' ') =Comp== '; // true
最後需要將" "轉換成"="再Post提交。這樣後台程式接受到的才是真正的空格。
關於encodeURIComponent,見MDC描述
encodeURIComponent escapes all characters except the following: alphabetic, decimal dis, - _ git )! 🎜>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 & Notin able" encodeURIComponent on this variable will give comment=Thyme &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 & ttime=again" 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 " " 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