Ajax Request garbled solution (Chinese garbled) _javascript tips

Source: Internet
Author: User

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

The following code:

Copy Code code as follows:

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:

Copy Code code 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.

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.