JQuery Ajax Save Data Chinese garbled solution

Source: Internet
Author: User


In the processing of a GB2312 coded Web site, with jquery Ajax submission, whether in the database, or load return page, the Chinese data has become garbled.
JQuery Ajax Chinese garbled reason is that JavaScript uses UTF-8 International code, UTF-8 each Chinese character is stored in 4 bytes. and my page and database are encoded with GB2312, which caused the AJAX send data when the Chinese garbled problem.



The solution is that all page-encoding declarations are utf-8, and databases, tables, and fields are utf-8.





The code is as follows

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

Mysql_set_charset (' UTF8 ')



"Three yards in one" refers to: "Database", "View", "code", the unity of coding. File storage is also UTF-8 encoded format.



Principles and more complex solutions, do not write more, use the time to search.



Inference: It seems to solve this Chinese garbled problem, you must give Ajax asynchronous submission of the specified display charset!



Look at the description of the Ajax tool function in jquery and discover that there is a parameter in the options that specifies Content-type, and add my Ajax code:


The code is as follows

JQuery (Form). Ajaxsubmit ({
URL: "Ajax.aspx?a=memberlogin",
Type: "Post",
DataType: "JSON",
ContentType: "application/x-www-form-urlencoded; Charset=utf-8 ",
Success:showloginresponse
});

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.