The space must be converted into a plus sign during Post submission.

Source: Internet
Author: User
The parameter contains spaces and must be converted to the plus sign when Post is used for submission. In this way, the background program receives the real space, if you are interested, you can find out that the serialize module of jQuery has an r20 regular expression.

The Code is as follows:


Var r20 =/% 20/g,


JQuery. in the param method, all "% 20" is converted to "+", that is, if the data contains spaces before the data is submitted, the space is converted to "% 20" after encodeURIComponent"

The Code is as follows:


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


Finally, you need to convert "% 20" to "=" and then submit the Post. In this way, the background program receives real spaces.

For more information about encodeURIComponent, see MDC description.

EncodeURIComponent escapes all characters should t 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 cocould 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 "+ ".

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.