How to solve Chinese garbled characters submitted by JQuery ajaxSubmit, jqueryajaxsubmit

Source: Internet
Author: User

How to solve Chinese garbled characters submitted by JQuery ajaxSubmit, jqueryajaxsubmit

The average user is

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, both Firefox and IE submit data are consistent and are UTF-8-encoded data.

Check the Header and find that the Content-Type in Entity is different.

In Firefox, Content-Type specifies the UTF-8 character set.

In IE, no character set is specified,

Obviously, by default, the character encoding submitted asynchronously by AJAX should be consistent with that of the webpage itself. That is to say, when the Server side does not find the character set specified by the display, using gb2312 to decode the data (but the data has been coded by the UTF-8 before submission), That's why garbled characters occur in IE, and in Firefox, when the browser submits AJAX data, the charset display is specified, causing the Server to use the UTF-8 to decode the data (correct decoding ).

Check JQuery's AJAX Tool Function Description and find that there is a specified content-type parameter in options.

Therefore, you must specify the encoding type during submission.

contentType: "application/x-www-form-urlencoded; charset=utf-8",

That is

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 content will share with you how to solve the Chinese Garbled text submitted by JQuery ajaxSubmit. I hope it will be helpful to you.

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.