Solution to the Problem of Chinese garbled characters transmitted in Ajax requests

Source: Internet
Author: User

Solution to the Problem of Chinese garbled characters transmitted in Ajax requests

Today, I encountered a problem with garbled characters concerning the transmission of Chinese Characters in ajax requests.

The following code:

function UpdateFolderInfoByCustId(folderId, folderName, custId) {$.ajax({type: "Post",contentType: "application/x-www-form-urlencoded; charset=utf-8",url: "http://localhost/CRM/Ashx/HandKBSucessCustomer.ashx?Method=UpdateCustomerByCustId&folderId=" + folderId + "&folderName=" + encodeURI(encodeURI(folderName)) + "&custId=" + custId,success: function (msg) {alert(msg);},error: function (error) {alert(error);}});}

If the above Code only transmits "& foderName =" + folderName, Chinese characters will produce garbled characters. If it is converted twice through encodeURL, the Chinese character encoding will become similar

"% E6 % b5 % 8b % eb % af % 95" format. After being converted to this format, transcoding is performed when obtaining it, as shown below:

public void UpdateCustomerByCustId(){int folderId = Convert.ToInt32(Request["folderId"]);string folderName = Request["folderName"];string folderName2 = Convert.ToString(System.Web.HttpUtility.UrlDecode(folderName));int custId = Convert.ToInt32(Request["custId"]);bool res = false;try{res = CustomerBusiness.UpdateCustomerByCustId(folderId, folderName2, custId);}catch (Exception ex){throw;}Response.Write(res);}}}

After this conversion, you can obtain the transmitted Chinese characters.

The above is a small series of solutions to the problem of transmitting Chinese garbled characters in Ajax requests. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. I would like to thank you for your support for the help House website.

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.