For the solution to converting the serialize method of jquery into a space of +, jqueryserialize

Source: Internet
Author: User

For the solution to converting the serialize method of jquery into a space of +, jqueryserialize

Jquery's serialize () method can be used to serialize individual tables. This is a convenient feature, but the following problems are found in actual use:
For example:
<Textarea name = "content"> abc 123 </textarea>
After the serialize () method is executed, the string abc + 123 is obtained;
That is, the serialization method of jquery escapes spaces and converts them to the plus sign (+.
Some code of the serialize method in jquery is as follows:
//.................
//.................
Return s. join ("&"). replace (// g, "+"); // replace the space with the + sign

After testing, the serialize () method escapes % 2B for the true "+", so you can safely Replace the result after serialize ().
Example:

<Textarea name = "content"> abc + 123 + 456 </textarea>

Jquery code:
Var a = $ ('$ frm1'). serialize (); // serialization. By default, encodeURIComponent () is called for encoding.
Alert (a); // content = abc ++ 123 ++ 456
Var B = a. replace (/\ +/g, ""); // g indicates that all matching strings are replaced.
B = decodeURIComponent (B); // decode the content after serialize.
Alert (B); // content = abc+ 123 + 456
So far, the problem has been solved.

Related Article

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.