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.