Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:43:44
Original
1503 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!