About the solution of the problem of transferring Chinese garbled in Ajax request _ajax related

Source: Internet
Author: User

Today encountered a problem, the AJAX request in the transmission of Chinese, encountered garbled problems.

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 code is only passed "&fodername=" +foldername words, Chinese characters will produce garbled, if after encodeurl conversion two times, encoding will become similar

The format of "%e6%b5%8b%eb%af%95". After converting to this format, at the time of obtaining the transcoding, as follows:

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, the transmitted characters can be obtained.

The above is a small set for you to introduce the AJAX request in the transmission of Chinese garbled problem solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. I also thank you for your support for the cloud-dwelling community 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.