Transfer Chinese parameter processing in JS Ajax

Source: Internet
Author: User

The Chinese parameter processing code is passed in Ajax:

The code is as follows

JS in:

Send_request (' ' + encodeuri (username) + ' &phone= ' + encodeuri (phone) + ' & Amp;content= ' + encodeuri (content));

In mini_do.php:

$username = UrlDecode ($_request[username]);
$phone = UrlDecode ($_request[phone]);
$content = UrlDecode ($_request[content]);

Finally, a friend said you can use the Escape function

var htmer = "getcode=" +escape (getcode) + "&content=" +escape (Content);

This I do not build righteousness oh, because it's a higher error. Some Chinese characters are not recognized, there is a function encodeuricomponent this is more comprehensive

encodeURIComponent, it is the Chinese, Korean and other special characters into the utf-8 format of the URL encoding, so if the background pass parameters need to use encodeURIComponent when the background decoding to Utf-8 support ( form is encoded in the same way as the current page encoding


Judging from the above

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,a-z

The coding range is the best choice for us to choose encodeURI.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.