오늘 저는 Ajax 요청에서 중국어를 전송하고 garbled 코드를 만나는 것에 관한 문제를 겪었습니다.
다음 코드 :
코드 사본은 다음과 같습니다.
함수 updatefolderInfoByCustid (folderid, folderName, custid) {
$ .ajax ({
유형 : "Post",
ContentType : "application/x-x-www-form-urlencoded; charset = utf-8",
URL : "http : //localhost/crm/ashx/handkbsucesscustomer.ashx? method = updatecustomerByCustid & folderid ="
+ folderid + "& folderName =" + encodeuri (encodeuri (folderName)) + "& custid =" + custid,
성공 : 기능 (msg) {
경고 (MSG);
},
오류 : 함수 (오류) {
경고 (오류);
}
});
}
위의 코드가 방금 전달되면 "& Fodername ="+FolderName이 있으면 중국어가 encodeurl에 의해 두 번 변환되면 중국어가 비슷해집니다.
"%E6%B5%8B%EB%AF%95"형식. 이 형식으로 변환 한 후 다음과 같이 획득 할 때 트랜스 코딩됩니다.
코드 사본은 다음과 같습니다.
공개 void updateCustomerByCustid ()
{
int folderid = convert.toint32 (요청 [ "folderid"]);
문자열 folderName = request [ "folderName"];
String FolderName2 = convert.ToString (System.Web.httputility.urlDecode (folderName));
int custid = convert.toint32 (요청 [ "custid"]);
bool res = false;
노력하다
{
res = customerbusiness.updatecustomerByCustid (FolderId, FolderName2, custid);
}
캐치 (예외)
{
던지다;
}
응답 (RES);
}
}
}
이 전환 후 전송 된 중국어를 얻을 수 있습니다.