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.