今日、私はAjaxリクエストで中国人の送信について問題に遭遇し、文字化けのコードに遭遇しました。
次のコード:
コードコピーは次のとおりです。
function updateFolderInFobycustid(folderid、foldername、custid){
$ .ajax({
タイプ:「投稿」、
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、
成功:function(msg){
アラート(MSG);
}、
エラー:関数(エラー){
アラート(エラー);
}
});
}
上記のコードが「&fodername = "+foldernameに渡された場合、漢字はcarledコードによって2回変換されると、漢字は似ています。
「%E6%B5%8B%EB%AF%95 "形式。この形式に変換した後、以下に示すように、取得するときにトランスコードされます。
コードコピーは次のとおりです。
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;
試す
{
res = customerbusiness.updatecustomerbycustid(folderid、foldername2、custid);
}
キャッチ(例外Ex)
{
投げる;
}
Response.write(res);
}
}
}
この変換の後、送信された漢字を取得できます。