JavaScript escape resolves filter url pass-value problem

Source: Internet
Author: User

Escape solve filter URL transfer value problem, when using Ajax to pass the value, encountered special symbol filtering problem, special symbol test

xml/html Code 01. Special Symbol Test HA: ~!@#$&%^* () <> how are you? <script>alert ("Hello World");</script>
Because there is a & symbol inside a special character, it is treated as a join symbol & when the data type passes multiple passes, so the string that follows is passed as a parameter value.

Solving method

Use should be encodeuricomponent, it is the Chinese, Korean and other special characters into the utf-8 format of the URL encoding, So if you need to use encodeURIComponent when passing parameters to the background, you need background decoding for utf-8 support (the form is encoded in the same way as the current page encoding)

Escape does not encode 69 characters: *,+,-,.,/,@,_,0-9,a-z,a-z

There are 82 encodeURI not encoded characters:!,#,$,&, ', (,), *,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,a-z

There are 71 encodeuricomponent characters that are not encoded:!, ', (,), *,-,.,_,~,0-9,a-z,


The solution is as follows (alternative solution):

JavaScript code

The code is as follows Copy Code
var tradition_content = Tradition_content.replace ("&", Escape (' & '));//tradition_content

The string to convert
To convert all &

  code is as follows copy code

var Repand = /&/g; 
var tradition_content = Tradition_content.replace (Repand, Escape (' & '));

//tradition_content the string to convert

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.