Solutions to data loss due to special symbols in AJAX post data

Source: Internet
Author: User

When you use AJAX to transmit data, the server side loses data when it has a plus (+), connector (&), or percent sign (%) data. Analyze the format of AJAX-transmitted data and JavaScript syntax:

1. "+" number: javascript resolves to a string connector, so "+" will lose the variable space when the server receives the data.

2. "&": javascript resolves to a variable connector, so when the server side receives the data, the data after the & symbol is lost.

The workaround is to replace the code with a regular expression (assuming that poststr is a string of data that you want to transfer via AJAX)

Poststr = Poststr.replace (/%/g, "%25");  Poststr = Poststr.replace (/\&/g, "%26");  Poststr = Poststr.replace (/\+/g, "%2b");  


Solutions to data loss due to special symbols in AJAX post data

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: 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.