Home  >  Article  >  Web Front-end  >  Explanation on converting spaces into plus signs when submitting using Post_javascript skills

Explanation on converting spaces into plus signs when submitting using Post_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:43:441538browse

There is a r20 regular expression in jQuery's serialize module

Copy code The code is as follows:

var r20 = / /g,

The jQuery.param method will convert all " " into " ", that is, before submitting the data, if the data contains spaces, after passing through encodeURIComponent, the spaces will be converted into " "
Copy code The code is as follows:

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

Finally, you need to convert " " to "=" before Post submission. In this way, what the background program receives is the real space.

For encodeURIComponent, see MDC description

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 &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 " " with " ".

Related :
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
http://www.w3.org/TR/html401/interact/ forms.html#form-content-type
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn