This article will share with you the solution to the problem of jquery ajax submit submitting Chinese garbled characters. Friends who are interested can follow me to learn
Most people use
jQuery(form).ajaxSubmit({ url: "ajaxsub.aspx?abc=test", type: "post", dataType: "json", success: data });
Analysis: JQuery's AJAX submission will encode the data to be submitted and use encodeURIComponent to process the data in js. Therefore, whether it is Firefox or IE, the submitted data is consistent and is UTF-8 encoded data.
Check the Header and find that there is a difference in the Content-Type in the Entity
In Firefox, the Content-Type specifies the character set as utf-8.
There is no character set specification in IE.
Obviously, by default, the character encoding of AJAX asynchronous submission should be consistent with the web page itself. In other words, there is no character set on the server side. It is found that when the displayed charset is specified, gb2312 is used to decode the data (but the data has been UTF-8 encoded before submission). This is the root cause of garbled characters under IE, while under Firefox, the browser is submitting When AJAX data is provided, the display specification of charset is added, causing the server to use UTF-8 to decode the data (correct decoding).
Check the description of JQuery's AJAX tool function and found that there is a parameter specifying content-type in options
So you must specify the encoding type when submitting
contentType: "application/x-www-form-urlencoded; charset=utf-8",
is as follows
jQuery(form).ajaxSubmit({ url: "ajaxsub.aspx?abc=test", type: "post", dataType: "json", contentType: "application/x-www-form-urlencoded; charset=utf-8", success: data });
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to solve the problem of Chinese garbled characters when JQuery ajax returns json
How to use ajax in Django framework post method
Detailed explanation of ajax jtemplate to implement dynamic paging
##
The above is the detailed content of How to solve the Chinese garbled code submitted by JQuery ajaxSubmit. For more information, please follow other related articles on the PHP Chinese website!