The phenomenon is as follows:
1 in Firefox, the processing of the page encoding for GB2312, the submission of data is not a problem, Chinese can be correctly resolved;
2 in IE8, the processing of the page encoding for GB2312, the submission of Chinese data garbled.
Whether it's $.post or $.ajax, or $.ajaxsubmit (from the form plug-in), there are no problems with the previous UTF-8-encoded site, which appears to have been caused by the coded format of the page that submitted the data. Anyway, since there is a difference between browsers, or from the HTTP package to see what the problem.
Open fiddle, respectively, using Firefox and IE to do an AJAX submission (take user login as an example), check their HTTP headers, find
1 The form data submitted by two browsers is consistent and is UTF-8 encoded, as shown in the following figure.
Analysis: jquery Ajax submission, will be submitted to the data to encode, using encodeURIComponent in JS processing data. Therefore, whether it is Firefox or IE, the submitted data are consistent, are UTF-8 encoded data.
2 Check header to find differences in Content-type in entity
In Firefox, Content-type specifies the character set as Utf-8.
In IE8, there is no character set designation.
Analysis: Obviously, by default, the character encoding of an AJAX asynchronous commit should be consistent with the Web page itself, that is, the server end uses GB2312 to decode the data without discovering the charset specified by the display (but the data was UTF-8 encoded before it was submitted), This is why under IE will appear garbled source, and in Firefox, the browser in the submission of AJAX data, coupled with the charset display specified, resulting in the server using UTF-8 to decode the data (correct decoding).
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:
Copy Code code 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
});
Test, ok!!!