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 }); |