Troubleshoot Ajax garbled characters

Source: Internet
Author: User
Tags php and mysql

Cause
There are two main reasons
1. The default character encoding of data returned by xtmlhttp is UTF-8. If the foreground page is gb2312 or other encoding data, garbled characters are generated.
2. The default character encoding for data submitted by the POST method is UTF-8. if the background is gb2312 or other encoding data, garbled characters are generated.

Solution
Further sorting
Recommended method. The front-end uses UTF-8 encoding, which saves a lot of trouble and fundamentally solves the garbled problem. the advantage is that it is highly efficient and conforms to the current format. UTF-8 encoding itself is a relatively good encoding with no language restrictions. disadvantage: You can only call your own background encoding or other UTF-8 encoding.
Front-end Code <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

Add the following to the first line of ASP in the background:CodeProgram code <% @ Language = "JavaScript" codePage = "65001" %>
<% Response. charset = "UTF-8"; %>
<% Session. codePage = 65001; %>

If the background contains HTML code, ensure that the program code <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

The remedy is to perform encoding conversion. You can perform encoding conversion on the client or the server. The advantage is that there are no restrictions and the disadvantage is low efficiency.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 772650

Related Article :
    • Generation and solution of page garbled characters in PHP and MySQL development phpme
    • Use JScript to encode form data with UTF-8 (in desperation) flylyke
    • A: "messageresource garbled in Linux" lovetide
    • On the issue of coding in J2EE development, UTF-8 is used to adapt to the multi-language J2EE development 2006-04-21 Faust
    • SQL Server Chinese garbled Analysis Solution: caihualin
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.