Ajax garbled !!!

Source: Internet
Author: User

 

1. The client uses the encodeuri or encodeuricompent parameter for UTF-8 encoding when submitting the request, and then sends it to the server. If the POST method is used, request. setcharacterencoding can be used to set the encoding used to interpret the parameter. If you use the get method, use the new string (Arg. getbytes ("iso-8859-1"), "UTF-8") method for transcoding.

 

2. when sending an Ajax request, use the POST method. Because Ajax uses UTF-8 encoding by default to submit parameters, if the file is not uploaded, set "application/X-WWW-form-urlencoded; charset =" UTF-8 "for the Content-Type request header of Ajax to notify the server that the client uses encoding to send parameters. In this way, the server can directly obtain the transcoded parameter value through string word = request. getparameter ("word");, saving request. setcharacterencoding.

.

On your page, you need to specify the page encoding, such as <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> 2. specify the output encoding on your server, such as response. charset = "UTF-8"; 3. the character encoding of front-end pages and backend pages must be UTF-8. In this way, the request will not be garbled. If the request is still garbled, you will use escape () to encode the request and then send it again, and then use Unescape () decode the request and then process it.

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.